Why this is not giving correct output?

Why this is not giving correct output?

You have to break from the while loop after intersection point is found. Because after that, both linked lists contain same nodes.


I made changes to your code. Please check it.

Okayy, Thanks Sir.
And Also As You have declared temp1 and temp2.
Even without it will work as we have not passed by reference.

Yes it will work without temp as well. But in linked list questions it is always suggested to declare a new pointer and work on it, rather than making changes to the passed head.

Please mark your doubt as resolved now.

Okayy Sir, Thanks.
And Please tell Can’t I mark the doubt resolved here only and give the 5* rating here?

Check your Ask Doubts section please. Some option must be coming over there.

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.