AlgoScope

Remove Nth From End

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

Linked list algorithms, algorithm, intermediate
Lead is at 4 and trail at 2.12345headtraillead
Lead is at 4 and trail at 2.12345headtraillead

Fast and Slow Pointers: Remove the 2nd from the end

Decision, step 4 of 6

Both move. Lead at 4, trail at 2.

How fast and slow pointers works

Cost

Best
O(n)
Average
O(n)
Worst
O(n)
Space
O(1)

Taught by the same lesson

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