How would you detect a cycle in a singly linked list without using extra memory, and why does your approach guarantee termination?
Now suppose you also need to return the exact node where the cycle begins. Walk me through the math proving why resetting one pointer to the head works.
What the Rubric Checks
- • States Floyd's tortoise-and-hare pointers accurately
- • Proves O(1) space and O(n) time complexity
- • Handles empty list and single-node edge cases
High-Scoring Answer Blueprint
Start with the hash-set baseline (O(n) time, O(n) space), then introduce fast (2x) and slow (1x) pointers. Explain that inside a cycle the relative speed is 1 node per step so they must collide in O(n) time with O(1) extra space.