0

Two pointers: opposite ends

Patternsused in ~100% of apps

The first pattern that feels like a trick. Two markers start at either end and walk towards each other, and a problem that looked like it needed every pair collapses into a single pass.

Core idea. Put one marker at each end. Compare, then move whichever one can be ruled out. Because each step permanently discards a possibility, the whole list is covered in one walk instead of every pair being tried.
Playground, this isn't a screenshot
sorted [2, 5, 9, 13, 20], looking for 25
2
L
5
9
13
20
R
= 22too small. Move left up
2
5
L
9
13
20
R
= 25found it

Two comparisons instead of ten. Each move ruled out four pairings at once.

↑ play a little first, then dig in