Find Middle
Slow moves one, fast moves two. When fast runs out, slow is halfway.
Fast and Slow Pointers: Find the middle of seven
Step 3: slow moves to 4, fast jumps two to 7. Fast has nowhere left to go.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Related
Leads to
Topics that need this one first.
Taught by the same lesson
Fast and Slow Pointers covers these too, in the same run.