206. Reverse Linked List
easyAsked at GustoReverse a singly linked list in-place. Gusto uses this to test pointer manipulation fundamentals and to see whether candidates can articulate the three-variable dance (prev, curr, next) before touching the keyboard.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Gusto loops.
- Glassdoor (2026-Q1)— Listed in Gusto phone-screen reports as a classic linked-list warm-up.
- Blind (2025-12)— Gusto SWE interview threads cite Reverse Linked List as an easy frequently paired with a follow-up on the recursive version.
Problem
Given the head of a singly linked list, reverse the list and return the reversed list's head.
Constraints
The number of nodes in the list is in the range [0, 5000].−5000 <= Node.val <= 5000.
Examples
Example 1
head = [1, 2, 3, 4, 5][5, 4, 3, 2, 1]Explanation: Each node's next pointer is flipped to point to its predecessor.
Example 2
head = [][]Explanation: Empty list reverses to empty list.
Approaches
1. Iterative (three-pointer)
Walk the list with prev, curr, and a saved next. At each step, flip curr.next to prev, then advance both pointers.
- Time
- O(n)
- Space
- O(1)
function reverseList(head) {
let prev = null;
let curr = head;
while (curr !== null) {
const next = curr.next; // save before overwriting
curr.next = prev; // reverse the pointer
prev = curr; // advance prev
curr = next; // advance curr
}
return prev; // prev is the new head
}Tradeoff: O(1) space, single pass. This is the preferred answer at Gusto. Naming prev/curr/next clearly signals pointer discipline.
2. Recursive
Recurse to the tail, then rewire next pointers on the way back up the call stack.
- Time
- O(n)
- Space
- O(n) call stack
function reverseList(head) {
if (head === null || head.next === null) return head;
const newHead = reverseList(head.next);
head.next.next = head; // the next node should now point back
head.next = null; // current node is now the tail
return newHead;
}Tradeoff: Elegant but uses O(n) stack space. Worth mentioning as the recursive formulation to show you know both approaches, but favour the iterative version in interviews.
Gusto-specific tips
Draw the three-pointer diagram before you code — interviewers at Gusto appreciate candidates who visualise a two-node list and trace through it step by step. Mention the null initialisation of prev (the sentinel for the new tail) and explain why you return prev not curr at the end. They'll also ask how you'd test the empty list and the single-node case.
Common mistakes
- Saving next after overwriting curr.next — always save next = curr.next before the pointer flip.
- Returning curr instead of prev at the end — curr is null after the loop, prev is the new head.
- Not handling the null head case — returning head immediately is the correct early exit.
- In the recursive version, forgetting to set head.next = null — the original head becomes the tail and must point to null.
Follow-up questions
An interviewer at Gusto may pivot to one of these next:
- Reverse only a sublist from position left to right (LC 92).
- Reverse the list in groups of k nodes (LC 25).
- How would you detect if the reversed list forms a palindrome?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why do you initialise prev to null?
After reversal the original head becomes the tail. It must point to null, which is what prev starts as — so when the loop processes the original head, it correctly sets its next to null.
What does the recursive approach return?
The deepest call returns the tail node (which becomes the new head). Every level passes this value back up unchanged — only the pointer wiring changes at each frame.
Is the recursive solution acceptable in a Gusto interview?
Yes, but call out the O(n) stack overhead. They may follow up asking if a very long list could cause a stack overflow, and how you'd handle that.
Practice these live with InterviewChamp.AI
Drill Reverse Linked List and other Gusto interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →