EasyLinked ListRecursionUpdated Sep 2026

206. Reverse Linked List

Asked at Google, Meta, Amazon, Microsoft and 4 more

Difficulty

Easy

Time

O(n)

Space

O(1)

Pattern

Linked List

Companies

8

Problem

Given the head of a singly linked list, turn the list around so the last node becomes the first, and return the new head.

You only have next pointers to work with, so the reversal is about repointing links — not about moving values.

Every arrow flips

before12345nullafter54321null
The nodes stay where they are; only the links change direction.

Constraints

  • ●The number of nodes is in the range [0, 5000]
  • ●-5000 <= Node.val <= 5000

Examples

Example 1
Inputhead = [1,2,3,4,5]
Output[5,4,3,2,1]
WhyEvery arrow flips direction, so 5 becomes the head and 1 becomes the tail.
Example 2
Inputhead = [1,2]
Output[2,1]
WhyA two-node list needs a single flip.
Example 3
Inputhead = []
Output[]
WhyAn empty list reverses to an empty list — return null.

Asked At

8 companies

How to Think About It

1

Use three pointers: prev (starts null), current (starts at head), next (temporary). At each step, reverse the current node's pointer to point backward.

2

The four-step dance at each node: (1) save next = current.next, (2) current.next = prev, (3) prev = current, (4) current = next.

3

When current becomes null, prev is the new head. The old head is now the tail (its next is null).

4

Recursive approach: reverseList(head.next) does the heavy lifting. Then head.next.next = head, head.next = null. Elegant but O(n) stack space.

Optimal Approach

Iterative:
Step 1: Initialize prev = null, curr = head.
Step 2: While curr is not null:
- Save next = curr.next
- curr.next = prev (reverse the pointer)
- prev = curr (move prev forward)
- curr = next (move curr forward)
Step 3: Return prev (the new head).

The key insight: you're reversing one pointer at a time. By the time curr reaches null, every pointer has been flipped.

Time: O(n). Space: O(1).

Walk with three pointers

12345nullprevcurrnextnext = curr.nextcurr.next = prevprev = curr, curr = nextLoop ends when curr is nullprev is the new head
Save next before flipping, or the rest of the list is lost the moment curr.next is overwritten.
ComplexityTime O(n)Space O(1)The iterative version rewires in place. The recursive version costs O(n) stack space.

What Trips People Up in Real Interviews

1

Not handling the edge case of an empty list or a single node. Return null or the node itself.

2

Losing track of the next node before reassigning pointers. Save next = current.next before setting current.next = prev.

3

Confusing iterative and recursive approaches. The iterative approach uses three pointers (prev, current, next). The recursive approach is elegant but uses O(n) stack space.

4

Forgetting to update the head. After the loop, the new head is prev (the last node you processed).

5

Trying to reverse by creating new nodes instead of re-pointing existing ones. The problem expects in-place reversal by changing pointers, not building a new list with copied values.

Solution Code

O(n) time
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def reverseList(head):
    prev, curr = None, head
    while curr:
        nxt = curr.next
        curr.next = prev
        prev = curr
        curr = nxt
    return prev

Pro at DSA?

Test your skills with a real FAANG-style mock interview.

Start a Mock Interview →

Frequently Asked Questions

What is the Reverse Linked List problem?

Given the head of a singly linked list, reverse it and return the reversed list. This is one of the most fundamental linked list problems and a building block for many harder questions.

How do you solve Reverse Linked List?

The optimal approach runs in O(n) time and O(1) space. Scroll up to "Optimal Approach" for the step-by-step walkthrough, diagrams, and code in Python, C++ and Java.

What companies ask Reverse Linked List?

Reverse Linked List is asked at Google, Meta, Amazon, Microsoft, Apple, Uber, Walmart, TikTok. It is a easy difficulty problem.

What are common mistakes on Reverse Linked List?
  • Not handling the edge case of an empty list or a single node. Return `null` or the node itself.
  • Losing track of the next node before reassigning pointers. Save next = current.next before setting current.next = prev.
  • Confusing iterative and recursive approaches. The iterative approach uses three pointers (prev, current, next). The recursive approach is elegant but uses `O(n)` stack space.
  • Forgetting to update the head. After the loop, the new head is prev (the last node you processed).
  • Trying to reverse by creating new nodes instead of re-pointing existing ones. The problem expects in-place reversal by changing pointers, not building a new list with copied values.