2
0
4
1
7
2
9
3
11
4
15
5
· target 13
AlgoPlus//structures / two-pointers
Read the theory

Two Pointers · Pair Sum

On a sorted array, converge two pointers to find a pair — no nested loop.

Target
13
Status
searching
Legend
Pointers L / R
Matching pair
AI Tutor Workspace
In a nutshell
The two-pointers trick puts one marker at each end of a sorted array and walks them toward each other. Because the array is sorted, the current pair's sum tells you which way to go: too small, move the left marker to a bigger value; too large, move the right marker to a smaller one. It finds a target pair in a single pass, with none of the nested looping a brute-force search would need.
Ready
Press play to begin the cinematic walkthrough.
On a sorted array, a left and right pointer converge: if the pair's sum is too small move left up, too large move right down — no nested loop.
Key terms
Go deeper in the lesson
Read the full theory, intuition & complexity for Two Pointers · Pair Sum.