Two Sum II — Input Array Is Sorted

In Two Sum (LC 1), you used a hash map because the array was unsorted. This array IS sorted. That changes everything — but can you articulate exactly why?

You probably already know how to find two numbers that add to a target in a sorted array. But I want to ask you something harder: can you prove that your approach never skips the answer?

Most readers can write the while (left < right) loop. Fewer can articulate why moving the left pointer past index 2 does not skip a valid pair at index 2. The gap between “I can do it” and “I know WHY it works” is where this explainer lives.

We will escalate through three approaches. The first two waste information in ways you will feel. There is a third approach. It requires the sorted property, and it will feel like cheating. By the end, you will articulate WHY it works — not just feel it, but state it precisely.

The Random Search

Given 12471115 and target = 13, find a pair that sums to the target. Tap two cells to form a pair — the array is sorted, but you are searching blind.

1
0
2
1
4
2
7
3
11
4
15
5

Tap a pair to check its sum. 0/15 pairs checked.