9. Reverse Linked List
easyAsked at RevolutReverse a singly linked list iteratively in place, a Revolut warm-up that mirrors replaying a chain of ledger entries in reverse to compute an as-of balance.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Problem
Given the head of a singly linked list, reverse the list and return the new head. Solve it both iteratively and recursively if asked.
Constraints
Nodes in [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. Stack push and rebuild
Push values onto a stack then pop into a new list.
- Time
- O(n)
- Space
- O(n)
const st = []; let cur = head;
while (cur){ st.push(cur.val); cur = cur.next; }
// rebuild from popped valuesTradeoff:
2. Iterative pointer swap
Walk once, flipping each next pointer with prev/curr/next. Constant space.
- Time
- O(n)
- Space
- O(1)
function reverseList(head){
let prev = null, curr = head;
while (curr){
const nxt = curr.next;
curr.next = prev;
prev = curr;
curr = nxt;
}
return prev;
}Tradeoff:
Revolut-specific tips
Revolut interviewers want you to draw the analogy to undoing a chain of double-entry postings — explicitly mention that each pointer flip must be atomic in a real ledger.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
Practice these live with InterviewChamp.AI
Drill Reverse Linked List and other Revolut interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →