Reverse Linked List

Reverse a singly linked list.

Pattern

Iterative Reversal

This problem follows the Iterative Reversal pattern, commonly found in the Linked List category. Recognizing this pattern is key to solving it efficiently in an interview setting.

Approach

How to Solve It

Track prev, curr, next. Point curr.next to prev, advance all three.

Key Insight

You only need three pointers (prev, curr, next) — save the next node before overwriting the pointer, then advance all three.

Step-by-step

  1. 1Initialize prev = null, curr = head
  2. 2While curr is not null:
  3. 3Save next = curr.next
  4. 4Reverse the pointer: curr.next = prev
  5. 5Move forward: prev = curr, curr = next
  6. 6Return prev (the new head)

Pseudocode

prev = null
curr = head
while curr:
    next = curr.next
    curr.next = prev
    prev = curr
    curr = next
return prev
Complexity Analysis

Time Complexity

O(n)

Space Complexity

O(1)
More Linked List Problems

Master this pattern with YeetCode

Practice Reverse Linked List and similar Linked List problems with flashcards. Build pattern recognition through active recall.

Practice this problem