How do you detect a cycle in a linked list?
Anonymous
Take two pointers. The first one traverses the linked list two nodes at a time. The second one traverses the linked list one node at a time. In a normal linked list, they should never refer to the same node. In a cycled linked list, the first one will get stuck in a cycle and eventually the second one will also, and at some point they will refer to the same node. If so, there's a cycle.
Check out your Company Bowl for anonymous work chats.