AlgoScope

Two Pointer Traversal

TechniquebeginnerArray Techniques

Two indices walk the array under a rule instead of a nested loop.

Decision · step 2 of 5Two Pointers: Two sum on a sorted array
1031426384115156leftright

1 + 15 = 16, too big. Only a smaller right value can help, so right moves down.

Open in the player →or start at step 2

What you will see

Two labelled pointers move independently; the rule that moves each one is the lesson.

How two pointers works →

Cost

BestO(n)
AverageO(n)
WorstO(n)
SpaceO(1)

How you work with it here

play it through, step one change at a time, scrub to any step, run it on your own input, predict what happens next.

Screen readers: Each cell is announced as index, value and state; each step's accessibility text states the decision and its effect.

Reduced motion: Swaps and shifts become value crossfades with an outline flash; pointers appear at their destination.

Before this

Leads to

Topics that need this one first.