How to Explain Reverse a Linked List in a Coding Interview (Step-by-Step)

How to Explain Reverse a Linked List in a Coding Interview (Step-by-Step)

Reverse a Linked List is one of the most common Easy-level questions asked at top tech companies. Most candidates know how to solve it — but fumble when it comes to explaining the pointer manipulation clearly under pressure.

In this post, you’ll learn exactly how to walk an interviewer through the problem: what to say, in what order, and which details to proactively highlight so you come across as confident and experienced.


Problem Statement

LeetCode 206 Easy

Given the head of a singly linked list, reverse the list and return the reversed list’s head.

Examples

Example 1
Input: head = [1, 2, 3, 4, 5]
Output: [5, 4, 3, 2, 1]
Example 2
Input: head = []
Output: []

Constraints

  • 0 <= number of nodes <= 5000
  • -5000 <= Node.val <= 5000

What Is the Problem?

Before writing a single line of code, restate the problem clearly in your own words:

“Given the head of a singly linked list, I need to reverse the direction of all the next pointers so the last node becomes the new head and the first node becomes the new tail.”

This shows the interviewer you’ve understood the problem — and buys you a few seconds to think.


Step 1: Start With the Brute Force (Then Dismiss It)

Never jump straight to the optimal solution. Acknowledge the naive approach first:

“One approach is to collect all node values into an array, reverse it, then rebuild the list. That works but it takes O(n) extra space — wasteful when we can do it in-place.”

Then pivot:

“A better approach is to reverse the next pointers in-place using three pointers — prev, curr, and next_node. That gives us O(n) time and O(1) space.”

Step 2: Explain the Algorithm in Plain English

Describe the approach out loud before touching code:

“I walk through the list one node at a time. For each node, I first save the next node so I don’t lose the rest of the list. Then I flip the current node’s pointer to point backward at prev. Then I advance both prev and curr one step forward. By the time curr is null, prev is sitting at the new head.”

Step 3: Talk Through the Code

Here’s the iterative Python solution with inline comments:

class Solution:
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        prev = None   # Will become the new tail (nothing behind head initially)
        curr = head   # Start at the head of the list

        while curr:
            next_node = curr.next  # Save next node before we overwrite the pointer
            curr.next = prev       # Flip the pointer — point backward instead of forward
            prev = curr            # Advance prev one step forward
            curr = next_node       # Advance curr one step forward

        return prev  # curr is None; prev is now the new head

Walk through it block by block using the example [1 → 2 → 3] to trace it visually if the interviewer seems uncertain.


Step 4: Highlight Edge Cases

This is where most candidates lose points. Call these out proactively:

1 Empty list (head = None)
“If the list is empty, curr starts as None so the while loop never runs and we return prev which is also None. Correct output with zero extra handling needed.”
2 Single node
“If there’s only one node, we save next_node as None, flip curr.next to prev (also None), then return that single node. Works correctly.”
3 Pointer save order
“The order of operations inside the loop is critical — you must save curr.next before overwriting it, otherwise you permanently lose the rest of the list.”

Step 5: State Time and Space Complexity

DimensionComplexityReason
Time O(n) We visit each node exactly once
Space O(1) Only three pointers, no extra data structure

Step 6: Mention the Easy-to-Miss Detail

prev is initialized to None — not to head. This is intentional: the original head becomes the new tail, so its next must point to None. Easy to get wrong if you’re rushing.”

Bonus: The Recursive Approach

Interviewers often follow up with “can you do it recursively?” Be ready:

class Solution:
    def reverseList(self, head: Optional[ListNode]) -> Optional[ListNode]:
        # Base case: empty list or single node — already reversed
        if not head or not head.next:
            return head

        # Recurse to the end — new_head will be the last node
        new_head = self.reverseList(head.next)

        # On the way back up: flip the pointer
        head.next.next = head  # Make the next node point back at current
        head.next = None       # Cut the forward pointer to avoid a cycle

        return new_head  # Bubble the new head all the way back up
“The recursive approach is elegant but uses O(n) space on the call stack — one frame per node. For very long lists this risks a stack overflow, so the iterative approach is preferred in production.”

Interview Checklist for Reverse a Linked List

  • Restate the problem — “reverse all the next pointers”
  • Mention the array approach, then explain why in-place is better
  • Explain the three-pointer technique in plain English before coding
  • Call out pointer save order — next_node must be saved before overwriting
  • Handle empty list and single node edge cases
  • Clarify why prev starts at None, not head
  • State O(n) time and O(1) space complexity
  • Mention the recursive alternative and its O(n) stack space tradeoff
  • Ask before coding, don’t just dive in

If you can solve Reverse a Linked List cleanly, try these next:

💡 Practicing your explanations out loud is just as important as writing correct code. The best candidates aren’t the ones who solve it fastest — they’re the ones who make the interviewer feel like they’re thinking alongside them.
Scroll to Top