Remove Cycle
After slow and fast meet, walk from the head and the meeting point to the entry, then once round the loop to cut the arrow before it.
List Pointer Puzzles: Cut a loop back to the third node
Slow to 2, fast to 3. Not the same node yet.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Taught by the same lesson
List Pointer Puzzles covers these too, in the same run.