Update appNew update is available. Click here to update.
sidenav-btnClose
Topic list
Intersection of Two Linked Lists
EASY
25 mins
131 upvotes
Linked List
Topics (Covered in this problem)
Problem solved
Badge
Skill meter
Linked List
-
-
Other topics
Problem solved
Badge
Skill meter
Strings
-
-
Matrices (2D Arrays)
-
-
Sorting
-
-
Binary Search
-
-
Stacks & Queues
-
-
Trees
-
-
Graph
-
-
Dynamic Programming
-
-
Greedy
-
-
Tries
-
-
Arrays
-
-
SQL
-
-
Binary Search Trees
-
-
Heap
-
-
Bit Manipulation
-
-
Solve problems & track your progress
Checkout your overall progress in every topic here
Become
userLevel
Sensei
in DSA topics
Open the topic and solve more problems associated with it to improve your skills
Check out the skill meter for every topic
See how many problems you are left with to solve for cracking any stage. Score more than zero to get your progress counted.

Intersection of Two Linked Lists

Contributed by
Arshit Babariya
Easy
yellow-spark
0/40
Avg time to solve 25 mins
Success Rate 73 %
Share
131 upvotes

Problem Statement

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.

For example:-

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.

alt.txt

Detailed explanation ( Input/output format, Notes, Constraints, Images )
Sample Input 1 :
4 1 8 -1
5 6 1 8 -1
4 5 -1
Sample Output 1 :
8
Explanation For Sample Input 1:
As shown in the diagram the node with data is 8 at which merging starts

Sample Input 1

Sample Input 2 :
1 9 1 2 -1
3 2 -1
4 -1
Sample Output 2 :
2
Sample Input 3 :
2 6 4 -1
1 5 -1
-1
Sample Output 3 :
-1
Reset Code
Full screen
Auto
copy-code
Console