Why is it giving wrong output?:Intersection pt of 2 linked list
hey @kamya, your approach is not correct ,if intersecting element present at the end of linked list it will always gives -1.
Correct approach: if n1> n2, than d=n1-n2. run loop d times on linked list 1 and change head1=head2->next. Else d=n2-n1. run loop d times on linked list 2 and change head2=head2->next.
Now both Linked list are of same length so compare each node of LL1 with LL2.
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.