Two Pointer Traversal
Two indices walk the array under a rule instead of a nested loop.
Two Pointers: Two sum on a sorted array
Find two values that add up to 14. The array is sorted, so start at both ends and let the sum tell you which pointer to move.
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.