PROBLEM 20 OF 75

Remove Nth Node From End of List

Remove the nth node from the end in one pass.

PATTERNLinked-list rewiringSave next before you change next.
SPOT THE SIGNAL

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Remove the nth node from the end in one pass.

WHY THIS FITS

A fixed gap lets the trailing pointer land before the removal node.

COMPLEXITY

O(n) time · O(1) space

COMMON FAILURE

Without a dummy node, removing the head needs a special case.

THE REASONING, IN ONE PLACE

How to solve Remove Nth Node From End of List

The goal is to solve this problem from the pattern, not to memorize a finished answer. Use this as a check after your own attempt.

What the question asks

Remove the nth node from the end in one pass.

Why Linked-list rewiring fits

A fixed gap lets the trailing pointer land before the removal node.

State to maintain

Dummy node plus fast and slow pointers n + 1 edges apart.

Transition

Advance fast, move both until fast ends, then bypass slow.next.

Time and space

O(n) time · O(1) space

Counterexample to the tempting mistake

Without a dummy node, removing the head needs a special case.

Prove it again tomorrow

Close this page. Rebuild the state and transition from memory, write a test that exposes the mistake above, then solve a fresh input without looking back. A same-day reread is practice, not proof of retention.

Open blank recall ↗