AlgoScope

Same Direction Pointers

AlgorithmbeginnerTwo Pointers

A reader scans ahead while a writer lags, compacting the array in place.

Decision · step 2 of 10Two Pointers: Remove duplicates
kept 0-01✓01122232435464758readwrite1 = 1

1 equals the last kept value, so it is skipped. The writer stays put.

Open in the player →or start at step 2

What you will see

The read pointer scans; the write pointer only advances when a value is kept.

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: Pointers announce their name and index; each step announces which pointer moved and why.

Reduced motion: Pointers appear at their new index with a brief emphasis instead of gliding.

Before this

Leads to

Topics that need this one first.