Patterns
FS · Pattern 03
Fast & Slow Pointers
Floyd's cycle detection: one pointer moves twice as fast. They'll meet if there's a cycle, or fast will hit null if there isn't.
- Time
- O(n)
- Space
- O(1)
Spot it when
- Detect cycle in linked list or array
- Find middle of linked list in one pass
- Detect if number is happy (infinite loop detection)
- Find start of cycle
Problems
Easy to hard · 0/4 solved