The Linked Lists, where a1, a2, c1, c2, c3 is the first linked list and b1, b2, b3, c1, c2, c3 is the second linked list, merging at node c1.
The input format contains three lines consisting of the front part of the first list, front part of the second list and the intersection part of the lists, respectively.
All lines contain the elements of the singly linked list separated by a single space and terminated by -1.
So the first line would contain
a1, a2, ...an, -1.
Similarly, the second line would contain
b1, b2, ...bm, -1.
Similarly, the third line would contain
c1, c2, ...ck -1.
The only output line contains data from the first merged node if the correct node is returned. If there is no merging or incorrect answer, the output contains -1.
You don't have to print by yourself explicitly. It has been taken care of. You need to return the first merged node.
Deletion In Doubly Linked List
Deletion In Doubly Linked List
Deletion In Doubly Linked List
Insertion In Doubly Linked List
Insertion In Doubly Linked List
Insertion In Doubly Linked List
Insertion In Doubly Linked List
LRU Cache
Delete Nodes On Regular Intervals
Add One To Linked List