BETA

Difficulty Level:

Easy

Total Submissions: 10983 Accuracy:

23.39%

Intersection of two sorted Linked lists (Function Problem)

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.


Input:

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.

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

Constraints:
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)

Input
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)

Output
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


					   
It is recommended to 'Compile & Test' your code before clicking 'Submit'!

Compilation/Execution Result:

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