Fast and Slow Pointers
One pointer moves twice as fast as the other. Finds middles and cycles in one pass.
Fast and Slow Pointers: Find the middle of seven
Step 1: slow moves to 2, fast jumps two to 3.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Leads to
Topics that need this one first.
Taught by the same lesson
Fast and Slow Pointers covers these too, in the same run.