How to find out if a linked list has a loop?
Anonymous
The hare and tortoise algorithm can be used. Start at node X and X+1. Have 2 pointers. One goes to next() and another goes to next().next() [twice as fast]. At some point, both pointers will be on same node Y. If you reach a null for second pointer, at any point, then there is no cycle.
Check out your Company Bowl for anonymous work chats.