+ 3
How do you find if there is any loop in singly linked list? How do you find the start of the loop
3 Answers
+ 8
What do you mean by loop?
0
Its pretty ingenious but what you do is that you have two pointers starting at the head of the list. The first you keep advancing by two nodes, the other by one node. If they ever land on the same node you have found a loop.
That algorithm blew my mind when I first heard about it :D