30. Reverse Linked List
easyAsked at RedditReverse a singly linked list. Reddit asks this to gauge pointer fluency — the most-asked easy LL problem. The skill maps directly to reversing chronological vote-event chains during fraud investigation.
By Sam K., Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Reddit loops.
- Glassdoor (2026-Q1)— Reddit phone screen — the must-know problem.
- Blind (2025-12)— Reported in nearly every Reddit on-site.
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 = [1,2][2,1]Example 3
head = [][]Approaches
1. Recursive
Reverse the rest, then flip the current node's pointer.
- Time
- O(n)
- Space
- O(n)
function reverseList(head) {
if (!head || !head.next) return head;
const newHead = reverseList(head.next);
head.next.next = head;
head.next = null;
return newHead;
}Tradeoff: Cleanest code but O(n) recursion stack. Risky for long lists.
2. Iterative three-pointer (optimal)
Track prev, cur, next. Re-point cur.next to prev, advance all.
- 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) memory. Both versions are interview-standard; iterative is production-safe.
Reddit-specific tips
Reddit interviewers expect both versions. Bonus signal: explain the recursive version's 'unwind' step — head.next.next = head flips the pointer on the way back up. Discuss when you'd prefer one over the other.
Common mistakes
- Forgetting head.next = null in the recursive version — creates a cycle.
- Iterative: forgetting to save next BEFORE re-pointing cur.next.
- Returning head instead of prev (head ends up at the original first node which is now last).
Follow-up questions
An interviewer at Reddit may pivot to one of these next:
- Reverse a linked list in groups of k (LC 25).
- Reverse between positions m and n (LC 92).
- Palindrome linked list (LC 234) — uses reverse-half.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why does head.next.next = head work in recursion?
head.next is the next node in the original list — but in the reversed list it should point back to head. We set it explicitly, then null out head.next.
When would I prefer recursive?
Almost never in production. Iterative is O(1) memory and safer for long lists.