Intersection of Two Linked Lists
Submissions: 21896   Accuracy:


  Difficulty: Easy   Marks: 2

Given two linked lists, the task is to complete the function findIntersection(), that returns the intersection of two linked lists. Each of the two linked list contains distinct node values.

The function takes 2 arguments, reference pointer to the head of the first linked list (head1) and reference pointer to the head of the second linked list (head2). There are multiple test cases and for each test case this function will be called separately.

The function should return reference pointer to the head of the new list that is formed by the intersection of the two the lists. 
Note: The new list formed should be in non-decreasing order. Also if there is no intersecting nodes among two linked lists, then print empty line.

User Task:
Since this is a functional problem you don't have to worry about input, you just have to complete the function findIntersection().

1 <= T <= 1000
1 <= N <= 103


9 6 4 2 3 8
1 2 8 6
2 6 8


** For More Input/Output Examples Use 'Expected Output' option **

Author: harshitsidhwa

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.

Need help with your code? Please use, generate link and share the link here.

to report an issue on this page.