Intersection of two sorted Linked lists
Submissions: 20551   Accuracy:


  Difficulty: Easy   Marks: 2
Associated Course(s):   Interview Preparation

Given two lists sorted in increasing order, create a new list representing the intersection of the two lists. The new list should be made with its own memory — the original lists should not be changed.

For example, let the first linked list be 1->2->3->4->6 and second linked list be 2->4->6->8, then your function should create a third list as 2->4->6.


You have to complete the method which takes 3 argument: the head of the first linked list , the head of second linked list and the head of the third link list which is to be created. You should not read any input from stdin/console. There are multiple test cases. For each test case, this method will be called individually.

Complete the Function given to produce the desired list with intersectioned values.

1 <=T<= 100
1 <= size of linked lists <= 100
1 <= Data in linked list nodes <= 1000


Example:(The input/output format below should be used for Expected Output only)

1                       -->  (No of test cases)
5 4                    -->  (sizes of linked lists)
1 2 3 4 6           -->  (Elements of 1st linked list) 
2 4 6 8              -->  (Elements of 2nd linked list)

2 4 6                 -->  (Elements of resultant 3rd linked list 


Note:The Input/Ouput format and Example given are used for system's internal purpose, and should be used by a user for Expected Output only. As it is a function problem, hence a user should not read any input from stdin/console. The task is to complete the function specified, and not to write the full code.

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

Contributor: Amit Khandelwal
Author: shef5

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

to report an issue on this page.