core pattern
Fast & Slow Pointers
Two pointers moving at different speeds through a sequence. Fast pointer moves 2x speed of slow. They meet if there's a cycle, or fast reaches the end for middle-finding.
Time
O(n)
Space
O(1)
🧠Mental Model
“Tortoise and hare on a circular track — if there's a loop, the hare will lap the tortoise.”
Verbal cue: Slow moves 1 step, fast moves 2 steps
🎯Recognition Triggers
When you see these patterns in a problem, consider this approach:
Cycle detectionFind middle of linked listHappy numberLinked list loop startPalindrome linked listCircular array loop
💡Interview Tips
- 1Explain WHY they meet: fast "gains" one node per iteration
- 2For cycle start: reset slow to head, move both at same speed
- 3This pattern proves O(1) space is possible for many linked list problems
- 4Draw the linked list and trace through with arrows
⚠️Common Mistakes
- ✕Not checking if fast.next exists before fast.next.next
- ✕Starting both pointers at head vs head.next for some variants
- ✕Confusing cycle detection with finding cycle start
- ✕Forgetting edge cases: null head, single node