Magicsheet logo

Reverse Linked List

Easy
48.3%
Updated 6/1/2025

Reverse Linked List

What is this problem about?

The Reverse Linked List interview question asks you to reverse a singly linked list in-place and return the new head. After reversal, the last node becomes the head, and all pointers are flipped so that each node points to its previous neighbor instead of its next. This is one of the most fundamental linked list operations in computer science.

Why is this asked in interviews?

This is asked at virtually every major company — J.P. Morgan, Apple, Uber, Goldman Sachs, Microsoft, Meta, Amazon, Google, Bloomberg, Adobe, and many more — because it is the building block for nearly every linked list problem. Reversing a linked list (both iteratively and recursively) is the basis for problems like Reverse Linked List II, Palindrome Linked List, Reorder List, and Reverse Nodes in k-Group. Mastering this one problem unlocks an entire family of harder problems.

Algorithmic pattern used

Two classic patterns: iterative and recursive. Iterative: use three pointers — prev = None, curr = head, nxt. At each step, save curr.next in nxt, set curr.next = prev, then advance prev = curr and curr = nxt. When curr is null, prev is the new head. Recursive: base case is an empty list or single node. Recursively reverse the rest, then make the original second node point back to the original head, and set the original head's next to None.

Example explanation

List: 1 → 2 → 3 → 4 → 5

Iterative process:

  • prev=None, curr=1: nxt=2, 1.next=None, prev=1, curr=2.
  • prev=1, curr=2: nxt=3, 2.next=1, prev=2, curr=3.
  • prev=2, curr=3: nxt=4, 3.next=2, prev=3, curr=4.
  • prev=3, curr=4: nxt=5, 4.next=3, prev=4, curr=5.
  • prev=4, curr=5: nxt=None, 5.next=4, prev=5, curr=None.

New head: 5. Result: 5 → 4 → 3 → 2 → 1.

Common mistakes candidates make

  • Saving curr.next AFTER updating it — always save nxt = curr.next BEFORE changing curr.next.
  • Forgetting to set the original head's next to None in the recursive approach, creating a cycle.
  • Returning curr instead of prev at the end of the iterative approach.
  • Not handling the edge case of an empty list or single-node list.

Interview preparation tip

For the Reverse Linked List coding problem, the linked list and recursion interview pattern is the foundation. Memorize both the iterative (three-pointer) and recursive versions — interviewers at Apple and Adobe often ask for both and compare tradeoffs (iterative is O(1) space; recursive is O(n) stack space). Practice drawing the pointer diagram step by step. Being fluent in this problem will significantly speed up your solutions to all related linked list problems.

Similar Questions