In-Place Linked List Reversal Pattern
In-Place Linked List Reversal flips the direction of a singly linked list (or a sublist within it) by rewiring `next` pointers as you walk through the nodes, using three local pointers and no extra storage. The technique handles full reversal, sublist reversal, and k-group reversal in O(n) time with O(1) space.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Complexity
- Time
- O(n)
- Space
- O(1)
When to use In-Place Linked List Reversal
- You need to reverse a singly linked list or a contiguous sublist of it.
- You need to reverse every k consecutive nodes (or alternate groups of k nodes).
- The problem disallows allocating a new list or recursive stack memory.
- You need to compare the original list against its reverse (palindrome check) in O(1) extra space.
- You need to rotate, reorder, or partition a list using reversal as a primitive.
Template
function reverseList(head) {
let previous = null;
let current = head;
while (current !== null) {
const next = current.next;
current.next = previous;
previous = current;
current = next;
}
return previous;
}Example LeetCode problems
| # | Problem | Difficulty | Frequency |
|---|---|---|---|
| 206 | Reverse Linked List | easy | foundational |
| 92 | Reverse Linked List II | medium | frequently asked |
| 25 | Reverse Nodes in k-Group | hard | company favorite |
| 24 | Swap Nodes in Pairs | medium | frequently asked |
| 234 | Palindrome Linked List | easy | frequently asked |
| 143 | Reorder List | medium | classic |
| 61 | Rotate List | medium | classic |
Common mistakes
- Forgetting to capture `current.next` in a temporary variable before rewriting `current.next`, which loses the rest of the list.
- Returning `current` (which is null at the end) instead of `previous` as the new head.
- On sublist reversal, forgetting to stitch the original predecessor's `next` to the new sublist head, which orphans the prefix.
- Off-by-one errors when counting k nodes for k-group reversal — verifying that a full group exists before reversing it.
- Using a dummy head only sometimes and then forgetting to skip it when returning, which exposes the dummy to the caller.
Frequently asked questions
Why use three pointers instead of two?
You need to remember the previous node (to set its `next` on the next iteration), the current node (to rewrite its `next`), and the original next node (so you don't lose the rest of the list when you overwrite the pointer). Two pointers is not enough.
How do I reverse only a sublist between positions left and right?
Walk to position left - 1 to capture the predecessor, run the standard reversal loop for right - left + 1 iterations, then reconnect: predecessor.next.next = current and predecessor.next = previous.
Should I use recursion or iteration?
Iteration is the canonical interview answer because recursion adds O(n) stack space and the problem usually requires constant space. Recursion can be elegant for sublist variants, but be ready to defend the space trade-off.
What is the dummy node trick?
A dummy node placed before the head turns the head-handling edge case into the same case as every other node. You return `dummy.next` instead of `head`, which avoids a special branch for reversing the very first node.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill the In-Place Linked List Reversal pattern under real interview conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →