
The first line of input contains an integer ‘T’, denoting the number of test cases. Then each test case follows.
The first line of each test case contains the elements of the first singly linked list separated by a single space.
The second line of each test case contains the elements of thesecond singly linked list separated by a single space.
For each test case, print a single line containing a linked list with common elements such that all common odd elements are before common even elements.
Output of each test case will be printed on a separate line.
You do not need to print anything, it has already been taken care of. Just implement the given function.
1 <= T <= 5
0 <= N <= 5 * 10 ^ 6
1 <= nodeVal[i] <= 10 ^ 9
Time Limit: 1 sec.
The idea is to traverse the list until one of them becomes NULL, and maintain two lists one for ‘even’ and one for ‘odd’. Append the even list after odd list.
Let ‘commonOddEven(head1, head2)’ be the function that returns the head of the common list.