Two Pointers
Two indices moving under a rule do in one pass what a nested loop needs n squared for.
Two Pointers: Two sum on a sorted array
Pair found at indices 1 and 5 in 3 steps. One pass, no nested loop.
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.