Code gives wrong answer!

Given 2 sorted linked lists , merge the two given sorted linked list and print the final Linked List.

Input Format
First Line contains T the number of test cases.
For each test case :
Line 1 : N1 the size of list 1
Line 2 : N1 elements for list 1
Line 3 : N2 the size of list 2
Line 4 : N2 elements for list 2

Constraints
1 <= T <= 1000
0<= N1, N2 <= 10^6
-10^7 <= Ai <= 10^7

Output Format
For each testcase , print the node data of merged linked list.

Sample Input
1
4
1 3 5 7
3
2 4 6
Sample Output
1 2 3 4 5 6 7
my code =>https://ide.codingblocks.com/s/352345

hello @Nikhil-Jettley-2567269533523013

a) dont print these arrows , check output format and print accordingly
image

b) u r taking O(n^2) to build a single linked list so most probably ur solution will give tle.

to overcome this instead for finding tail again n again , store it in some pointer and then use it for insertion at end in O(1) (per insertion)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.