Skip to content

In-Place Reversal

Also known as: Pointer Rewiring, Iterative Linked-List Reversal

Walk the list holding three references — previous, current, and next — and flip each node's pointer backwards as you pass. The entire pattern is "save the next node before you overwrite the link, or you lose the rest of the list."

Before you start

What 'solved properly' looks like

Target: O(n) time, O(1) space. If your solution is slower than that, you've found a solution but not this pattern — the judge says "Accepted" either way, so treat this as your real benchmark.

The idea

You walk the list with three pointers: previous (the node already rewired), current (the node you're about to rewire), and next (the rest of the list you'd lose if you weren't holding onto it). For each node, you save next, point current back to previous, then advance all three forward. When current reaches the end, previous is the new head.

Why it matters: It's the base move for a whole family of linked-list problems — reversing a sublist, swapping adjacent nodes, checking palindromes by reversing the second half. Getting the pointer-order discipline right here makes every harder linked-list problem click.

When to reach for it

Reach for it when the problem says "reverse the list", "reverse a sublist", "reorder a list", "swap adjacent nodes", or "check if a linked list is a palindrome." Also when the problem demands O(1) space — if extra memory is allowed, you could just copy the values.

When not to use it

A dummy head is most useful when reversing a sublist that may begin at the actual head — it eliminates the special case of rewiring the head node. For a standard whole-list reversal, the three-pointer loop alone is sufficient. And a recursive reversal is elegant but costs O(n) stack space, so it isn't actually in-place; if the problem demands O(1) space, iterate.

Practice set

Work these top to bottom. The time-box is a cue to pause and re-read the triggers above if you're still stuck when it passes — not a deadline to race. Getting unstuck by stepping back is the skill being trained.

# Problem Where Difficulty Time-box Role
1 Reverse Linked List LeetCode Easy 15 mins teaching
2 Swap Nodes in Pairs LeetCode Medium 20 mins teaching
3 Palindrome Linked List LeetCode Easy 20 mins consolidation
4 Reverse Linked List II LeetCode Medium 25 mins consolidation
5 Reorder List LeetCode Medium 35 mins challenge

Already know this? Test out.

If you can solve Reorder List cleanly in one sitting — combining the middle-finding, reversal, and merging steps without a hint — you already own this pattern, so move on to the next one. If it tangles you up, that's your signal to work the set from the top instead of skipping.


← Fast & Slow Pointers  ·  Stack Matching → Back to the roadmap