Floyd's Tortoise and Hare: Linked List Cycle Detection in Java, With the Proof
“Detect a cycle in a linked list.” Everyone recites it: slow moves one step, fast moves two, if they meet there’s a cycle. Then the interviewer says “why can’t fast skip over slow?” and the room goes quiet. Then “find where the cycle starts” — and the memorized answer runs out. Floyd’s tortoise and hare is a two-minute algorithm with a twenty-minute understanding. Here’s the understanding. The shallow answer (and why interviewers hate it) The HashSet version works and every candidate knows it: ...