LazyCoder

Reverse a Linked List

Practice reversing a singly linked list and see how head, temp, and prev change at every step.

Author and page trust

Written by Vignesh Reddy Julakanti.

Founder of Engineering Animuthyam.

Published: 2026-03-22. Updated: 2026-04-02.

This page is written for learners who need visual, interview-oriented linked list explanations rather than a short definition.

Learning outcomes

  • Track the current node without losing the rest of the list.
  • Understand why prev becomes the new head.
  • Recognize the safe order for pointer rewiring.

What to focus on

Reversal is not about memorizing a pattern. It is about preserving access to the remaining nodes while you redirect the current next pointer. This page keeps the visual state and code trace in sync so the sequence is explicit.

Interview value

This is one of the most common linked list interview exercises because it tests pointer discipline. If you can explain the order of assignments clearly, you usually understand the structure well enough to handle harder variants.

Where people actually fail

Learners usually know the three variables by name but still lose the chain during the second or third iteration. The failure is almost always about sequence, not syntax. This page is built to make that sequence obvious.

Worked example

  1. Start with A -> B -> C -> D -> E and set prev to null.
  2. Move head one node forward, then point the current node back to prev.
  3. Repeat until head becomes null, then assign prev to head.

When to use this tool

  • Interview preparation for one of the most common pointer-manipulation questions.
  • Revision before solving palindrome, reorder-list, or sublist-reversal problems.
  • Building intuition for in-place linked list mutation.

Edge cases to review

  • An empty list where head starts at null.
  • A single-node list that should remain valid after reversal.
  • A reversal attempt where the old head forgets to terminate at null.

Interview variants

  • Reverse the entire list iteratively.
  • Reverse the first k nodes or a bounded sublist.
  • Explain recursive reversal after proving the iterative version first.

Practice checklist

  • Say what each variable protects before every iteration.
  • Check that the current node is detached only after the next node is saved.
  • Confirm that the old head becomes the new tail and ends at null.
  • Run the same trace on a 2-node and 1-node list.

FAQ

Why do we need a temp variable?

Without temp, you can lose access to the current node or the remainder of the list while rewiring pointers.

What should the last node point to after reversal?

The original head becomes the last node, so its next pointer must end at null.