Reverse Linked List

Free with account Updated Nov 19, 2026 · 4 min read
On this page

    Problem statement

    Given the head of a singly linked list, reverse the list and return the new head. Change the links, not the values, and use O(1) extra space for the iterative version.

    Short, common, and unforgiving: three pointers, four lines, and one wrong order loses the rest of the list. It's also a building block for harder problems (reverse in groups, palindrome lists, reorder list). Original problem: LeetCode 206.

    Example

    The list 1 → 2 → 3 → 4 becomes 4 → 3 → 2 → 1, and the old last node is the new head.
    The list 1 → 2 → 3 → 4 becomes 4 → 3 → 2 → 1, and the old last node is the new head.
    Input:  1 -> 2 -> 3 -> 4 -> null
    Output: 4 -> 3 -> 2 -> 1 -> null
    Input:  null
    Output: null

    Constraints (assumed)

    • 0 ≤ number of nodes ≤ 5,000.

    What this question tests

    • Careful pointer manipulation in the right order.
    • Knowing both the iterative (O(1) space) and recursive versions and their costs.
    • Handling empty and one-node lists without special cases.

    Questions to ask first

    1. Can I modify the list in place? (Here: yes; reverse the links.)
    2. Singly or doubly linked? (Here: singly.)
    3. Iterative or recursive? Either is accepted; mention the stack cost of recursion.
    4. Reverse the whole list or a part? (Here: the whole list; partial reversal is a follow-up.)