Intersection of Linked List Problem Statement

You are provided with two singly linked lists of integers. These lists merge at a node of a third linked list.

Your task is to determine the data of the node where merging begins. If there is no intersection, return -1.

Example:

Input Format:
The input format consists of three lines, each representing a singly linked list.
Each line contains the elements of a singly linked list separated by a space and terminated by -1.
For instance, the first linked list might look like: a1 a2 ... an c1 -1.
The second line could be: b1 b2 ... bm c1 -1.
The third line might be: c2 c3 ... ck -1.
Output Format:
Your output should be a single line that contains the data of the first merged node.
If there is no intersection, output should be -1.
You do not need to print anything explicitly; it is handled for you.

Constraints:

  • 0 ≤ N ≤ 105
  • 0 ≤ M ≤ 105
  • 0 ≤ K ≤ 105
  • -109 ≤ data ≤ 109, and data ≠ -1
  • Time Limit: 1 second
Be the first one to answer
Add answer anonymously...
Ernst & Young Associate Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter