DSA · interactive
Fast and slow pointers
Does this linked list loop back on itself? Send two pointers along it, one twice as fast. If there's a loop, the fast one laps the slow one and they meet. No extra memory needed.
Phase 1: is there a cycle?
- 0slowfast→
- 1→
- 2→
- 3→
- 4→
- 5→
- 6→
- 7
- → back to 3
Both start at the head. Slow moves 1 step, fast moves 2.
The list
1 Slow takes one step, fast takes two, every round.
slow = slow.next; fast = fast.next.next
2 3 4
Now solve it
Linked List: 10 problems
See all →In production
Tools and technologies
Floyd's trick appears wherever memory is tight.
Not tied to one language — use these names when you search docs or design a system.