Intersection of Linked List Problem
You are provided with two singly linked lists containing integers, where both lists converge at some node belonging to a third linked list.
Your task is to determine the data of the node at which they start merging. If no merging occurs, return -1.
Example:
The linked lists are structured as follows:
First Linked List: a1, a2, c1
Second Linked List: b1, b2, b3, c1
Third Linked List where merging occurs: c1, c2, c3
An image shows the merging:

Input:
Three lines representing three singly linked lists.
Each line contains elements separated by spaces, ending with -1.
Line 1 (First linked list): a1, a2, ...an, c1, -1
Line 2 (Second linked list): b1, b2, ...bm, c1, -1
Line 3 (Third linked list): c2, c3, ...ck, -1
Output:
A single integer representing the data of the node where the merging starts. Output -1 if no merging occurs.
You don't need to print this yourself as it is managed automatically.
Constraints:
- 0 ≤ N ≤ 105
- 0 ≤ M ≤ 105
- 0 ≤ K ≤ 105
- -109 ≤ data ≤ 109 and data ≠ -1
- Time Limit: 1 second

AnswerBot
4mo
Find the node where two linked lists merge, return -1 if no merging occurs.
Traverse both lists to find their lengths and the difference in lengths
Move the pointer of the longer list ahead by the diffe...read more
Help your peers!
Add answer anonymously...
Bounteous x Accolite Software Developer Intern interview questions & answers
A Software Developer Intern was asked Q. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer Intern was asked Q. Median of Two Sorted Arrays Given two sorted arrays A and B of sizes N and M, fi...read more
A Software Developer Intern was asked Q. Distance Between Two Nodes in a Binary Tree Given a binary tree and the values o...read more
Popular interview questions of Software Developer Intern
A Software Developer Intern was asked Q1. Ninja and the Maze Problem Statement Ninja is stuck in a maze represented as a 2...read more
A Software Developer Intern was asked Q2. Median of Two Sorted Arrays Given two sorted arrays A and B of sizes N and M, fi...read more
A Software Developer Intern was asked Q3. Distance Between Two Nodes in a Binary Tree Given a binary tree and the values o...read more
>
Bounteous x Accolite Software Developer Intern Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

