206. Reverse Linked List
easyAsked at eBayLinked list manipulation is a staple of eBay's entry-level interview loop. Think of it as reversing the order of items in a payment processing queue — a concrete scenario where pointer manipulation and in-place operations matter for memory efficiency at the scale of millions of concurrent transactions.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in eBay loops.
- Glassdoor (2026-Q1)— eBay SWE candidates report Reverse Linked List as a common warm-up in phone screens testing pointer comfort.
- Blind (2025-11)— Listed in eBay new-grad interview prep threads as a high-probability easy linked list question.
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: The list is reversed in place; the former tail becomes the new head.
Example 2
head = [1,2][2,1]Explanation: Two-node case — the single pointer reversal is the same logic.
Example 3
head = [][]Explanation: Empty list returns null.
Approaches
1. Iterative (in-place)
Track three pointers — prev, curr, and next. In each iteration, reverse curr's next pointer to point to prev, then advance all three pointers forward.
- Time
- O(n)
- Space
- O(1)
function reverseList(head) {
let prev = null;
let curr = head;
while (curr !== null) {
const next = curr.next; // save next 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) extra space — the preferred answer at eBay. Walk through a 3-node example on the whiteboard to prove correctness before coding.
2. Recursive
Recurse to the tail, then on the way back up, reverse each node's next pointer.
- 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; // reverse the link
head.next = null; // cut the old forward link
return newHead;
}Tradeoff: Elegant but uses O(n) call-stack space — a concern for very long lists (stack overflow). Offer the iterative solution as the production choice.
eBay-specific tips
eBay interviewers expect you to draw the pointer state on paper (or a whiteboard) before coding — 'prev → null, curr → head, we move forward one node at a time.' Articulate the null-check for an empty or single-node list. Senior interviewers will ask about stack-overflow risk of the recursive approach; answering with O(n) stack space earns respect. The 'how would this perform at scale' follow-up here is about stack depth on lists with millions of nodes.
Common mistakes
- Losing the reference to next before overwriting curr.next — always save next = curr.next first.
- Returning curr instead of prev at the end — curr is null when the loop exits; prev holds the new head.
- Not handling the empty list (head === null) — this should return null immediately.
- In the recursive version, forgetting to set head.next = null — this leaves a cycle in the list.
Follow-up questions
An interviewer at eBay may pivot to one of these next:
- Reverse Linked List II (LC 92) — reverse only a subrange [left, right] of the list.
- Palindrome Linked List (LC 234) — reverse the second half and compare with the first.
- How would you reverse a doubly-linked list?
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why is prev initialized to null?
The original head becomes the new tail; its next pointer must be null. Initializing prev to null ensures this without a special case.
When would the recursive approach be acceptable in production?
Only when list length is bounded and small (e.g., a config list). For unbounded user data at eBay's scale, always prefer the iterative approach.
Can you do it with a stack?
Yes — push all values, then pop into a new list. But that's O(n) space and O(n) time with larger constants. It's acceptable to mention but the in-place iterative solution is expected.
Practice these live with InterviewChamp.AI
Drill Reverse Linked List and other eBay interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →