AlgoScope

Two Sum (sorted)

Too small, move left up. Too big, move right down. The sorted order makes that safe.

Two pointers, algorithm, beginner
1 plus 11 is 12. Less than the target, so the left pointer moves to index 1.1031426384115156leftright
1 plus 11 is 12. Less than the target, so the left pointer moves to index 1.1031426384115156leftright

Two Pointers: Two sum on a sorted array

Decision, step 3 of 5

1 + 11 = 12, too small. Only a bigger left value can help, so left moves up.

How two pointers works

Cost

Best
O(1)
Average
O(n)
Worst
O(n)
Space
O(1)

Leads to

Topics that need this one first.

Taught by the same lesson

Two Pointers covers these too, in the same run.