04 Try it yourself Interactive

Walk the pointers, one press at a time

The two amber cells are the pair being added right now, and the labels underneath show where each pointer stands. Grey cells have been ruled out and will never be looked at again. It opens on the nested loop so you can count its checks first; switch to the Two pointers tab to watch the walk reach the same answer in far fewer. Press Next to advance and Back to undo. Nothing moves on its own.

Brute force · every pair
target 10 · O(n²)
2–8 whole numbers (0–99) and a target. Unsorted input gets sorted for you.
Press Next to begin. Each press moves one step.


      
left index
right index
pair sum
comparisons0
step 0 / 0