PROBLEM 19 OF 75

Reorder List

Reorder nodes first, last, second, second-last, in place.

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

Why does this pattern fit?

FRAME · 1 OF 4

Restate the exact job

Reorder nodes first, last, second, second-last, in place.

WHY THIS FITS

The target order interleaves the first half with the reversed second half.

COMPLEXITY

O(n) time · O(1) space

COMMON FAILURE

Not severing the halves can create a cycle.

THE REASONING, IN ONE PLACE

How to solve Reorder 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

Reorder nodes first, last, second, second-last, in place.

Why Linked-list rewiring fits

The target order interleaves the first half with the reversed second half.

State to maintain

Middle pointer, two half heads, and saved next references.

Transition

Find the middle, reverse the second half, then weave alternating nodes.

Time and space

O(n) time · O(1) space

Counterexample to the tempting mistake

Not severing the halves can create a cycle.

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 ↗