TLE error appeared


i had written this code for l=merging two array. How can i optimize this code as it’s giving TLE in the coding block compiler.

or should i use list stl here?

hi @mvermav19, just define head1, head2 inside while function
`int t;
cin >> t;

while (t)
{
node *head1 = NULL;
node *head2 = NULL;

`
like this

but why does this issue appeared?
Like if we are forming any functionality on linked list then we are supposed to initialize it inside the loop??

@mvermav19 everytime start with null else it will keep adding to the prev head only
eg 1 2 3 was in head1 in test case 1
then in two it will be 1 2 3 4 5 6
not 4 5 6 it will keep adding in prev list so make null everytime

oohkay
Understood now
Thanks a lot!

1 Like

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.