Count triplets in a sorted doubly linked list whose sum is equal to a given value x
Deletion in Circular Linked List
Intersection of Two Linked Lists
Last Updated: 23 Feb, 2023
Avg time to solve 25 mins
Success Rate 73 %
You are given two Singly Linked List of integers, which are merging at some node of a third linked list.
Your task is to find the data of the node at which merging starts. If there is no merging, return -1.
The given Linked Lists, where a1, a2, c1 is the first linked list, b1, b2, b3, c1 is the second linked list, and c1, c2, c3 is the third linked list which are merging at node c1.
Detailed explanation ( Input/output format, Notes, Images )
The input format contains three lines consisting of three singly-linked lists.
All three lines contain the elements of the singly linked list separated by a single space and terminated by -1.
So first linked list would contain
a1, a2, ...an, c1, -1.
Similarly, the second line would contain
b1,b2, ...bm, c1, -1.
The third line would contain
c2, c3, ....ck, -1.
Output format :
The only line of output contains data of the first merged node. If there is no merging output should contain -1.
You don't have to explicitly print by yourself. It has been taken care of.
0 <= N <= 10^5
0 <= M <= 10^5
0 <= K <= 10^5.
-10^9 <= data <= 10^9 and data != -1
Time Limit: 1 sec
Sample Input 1 :
4 1 8 -1
5 6 1 8 -1
4 5 -1
Sample Output 1 :
Explanation For Sample Input 1:
As shown in the diagram the node with data is 8 at which merging starts