//wrong output///

please check my code

Hey Aparna, after seeing ur code i found that
1)you are taking (cin>>data) outside your while loop because of which the linked list is not getting
built correctly.Like for n=1, ur buildnode function will first (cin>>data) , insert this data in the linked
list and will (cin>>data) again (being in the while loop) which is not required.So, take (cin>>data)
only once inside while loop and before insertattail function .
2)Try to put head1 and head2 inside while(t>0) loop instead of outside it. In every testcase, you need
to consider a new linked list. If head1 and head2 are outside while(t>0), in every test case, size of
head1 and head2 will go on increasing and because of that you would be getting wrong answer.
Hope that resolves your doubt.

yes it got submitted successfully. Thanks a lot :slight_smile:

1 Like