29. Reverse Linked List
easyAsked at VercelReverse a singly linked list in-place. Vercel asks this constantly because it's the building block of every list-manipulation problem they care about — and because they want to see if you can do both iterative and recursive cleanly.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Vercel loops.
- Glassdoor (2025-Q4)— Vercel screen warm-up; both iterative and recursive expected.
- Blind (2026-Q1)— Listed in Vercel platform onsite recap.
Problem
Given the head of a singly linked list, reverse the list, and return the reversed list.
Constraints
The number of nodes in the list is the range [0, 5000].-5000 <= Node.val <= 5000
Examples
Example 1
head = [1,2,3,4,5][5,4,3,2,1]Example 2
head = [][]Approaches
1. Convert to array, reverse, rebuild
Walk to collect values; reverse the array; build a new list.
- Time
- O(n)
- Space
- O(n)
function reverseList(head) {
const vals = [];
let cur = head;
while (cur) { vals.push(cur.val); cur = cur.next; }
vals.reverse();
let dummy = { val: 0, next: null }, tail = dummy;
for (const v of vals) { tail.next = { val: v, next: null }; tail = tail.next; }
return dummy.next;
}Tradeoff: O(n) extra space and allocates n new nodes. Mention as the obvious non-answer.
2. Iterative three-pointer (optimal)
Walk the list; for each node, save next, point current at prev, slide prev/current forward.
- Time
- O(n)
- Space
- O(1)
function reverseList(head) {
let prev = null;
let cur = head;
while (cur) {
const next = cur.next;
cur.next = prev;
prev = cur;
cur = next;
}
return prev;
}Tradeoff: O(1) extra space, in-place. The three-pointer dance is the canonical answer for any list-reverse follow-up.
Vercel-specific tips
Vercel will accept the iterative version, then ask for recursion. Both should be ready: `if (!head || !head.next) return head; const rest = reverseList(head.next); head.next.next = head; head.next = null; return rest;`. Bonus signal: drawing the pointer diagram out loud as you write.
Common mistakes
- Forgetting to save next BEFORE overwriting cur.next — loses the rest of the list.
- Returning head instead of prev — returns the old head, which is now the tail.
- In the recursive version, forgetting `head.next = null` — creates a 2-cycle at the original head.
Follow-up questions
An interviewer at Vercel may pivot to one of these next:
- Reverse a range [m, n] (LC 92).
- Reverse nodes in k-groups (LC 25, hard).
- Reverse a doubly linked list.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why three pointers?
You need prev (to attach to), cur (to modify), and next (to advance to). Without next, overwriting cur.next loses your forward pointer.
Iterative vs recursive — which does Vercel prefer?
Iterative for safety (O(1) stack). Be ready to write both — they often ask 'now do it recursively' after you finish the iterative.
Practice these live with InterviewChamp.AI
Drill Reverse Linked List and other Vercel interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →