Two Sum (sorted)
Too small, move left up. Too big, move right down. The sorted order makes that safe.
Two Pointers: Two sum on a sorted array
1 + 11 = 12, too small. Only a bigger left value can help, so left moves up.
Cost
- Best
- O(1)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(1)
Before this
Leads to
Topics that need this one first.
Taught by the same lesson
Two Pointers covers these too, in the same run.