if you take 5 nodes and loop starts from 2 and ends at 5 then the distance from head of starting of loop if 1 and distance from fast pointer is 3 it is stuck in infinite loop as they never meet
Not able to get theorem
It will not enter an infinite loop.
The theorem proves that the fast pointer and the slow pointer will meet at some moment.
If you want the Theorem’s proof, you can google it and check
1->2->3->4->5->2 can u plz tell in this case plz
It will only work for linked lists having cycle.
Draw the structure of the linked list and visualized.
Just imagine that if there is a circular race track, and two players are running.
Player 2 runs at a speed greater than player 1, then obviously there will be a point where player 2 meets player 1
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.