Reverse Array
Swap the outermost pair and step both pointers inward until they meet.
Two Pointers: Reverse in place
The pointers meet on 4. The middle value never moves.
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
Two Pointers covers these too, in the same run.