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
Given the head of a singly linked list, reverse the list and return the reversed list’s head.
Examples
Output: [5, 4, 3, 2, 1]
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 thenextpointers in-place using three pointers —prev,curr, andnext_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 atprev. Then I advance bothprevandcurrone step forward. By the timecurris null,previs 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:
head = None)“If the list is empty,currstarts asNoneso the while loop never runs and we returnprevwhich is alsoNone. Correct output with zero extra handling needed.”
“If there’s only one node, we savenext_nodeasNone, flipcurr.nexttoprev(alsoNone), then return that single node. Works correctly.”
“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
| Dimension | Complexity | Reason |
|---|---|---|
| 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
“previs initialized toNone— not tohead. This is intentional: the original head becomes the new tail, so itsnextmust point toNone. 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_nodemust be saved before overwriting - Handle empty list and single node edge cases
- Clarify why
prevstarts atNone, nothead - 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
Related Problems to Practice
If you can solve Reverse a Linked List cleanly, try these next:
