AlgoScope

Remove Nth From End

AlgorithmintermediateLinked List Operations

Lead one pointer n ahead, then walk both until the leader runs out. Trail is just before the target.

Decision · step 4 of 6Fast and Slow Pointers: Remove the 2nd from the end
12345headtraillead

Both move. Lead at 4, trail at 2.

Open in the player →or start at step 4

What you will see

A fixed gap of n between two pointers; when the front one ends, the back one is just before the target.

How fast and slow 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, try operations in any order.

Screen readers: Each node announces its value and what it points to; each step announces the pointer change ("node 3 now points to node 5").

Reduced motion: Pointer arrows redraw in place with a brief emphasis instead of animating the detach and reattach.

Taught by the same lesson

Fast and Slow Pointers covers these too, in the same run.