13. Reverse Linked List
easyAsked at Riot GamesReverse a singly linked list in place — a pointer-manipulation warm-up Riot uses before scaling up to replay-buffer reversal questions.
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 iteratively in O(1) extra space.
Constraints
0 <= nodes <= 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 copy
Push all values onto a stack and pop them into a new list.
- Time
- O(n)
- Space
- O(n)
const s = [];
let n = head;
while (n) { s.push(n.val); n = n.next; }
let d = new ListNode(0), t = d;
while (s.length) { t.next = new ListNode(s.pop()); t = t.next; }
return d.next;Tradeoff:
2. Iterative pointer flip
Walk the list, flipping each node's next pointer to its predecessor using a three-pointer dance. Same in-place reversal pattern Riot uses to rewind replay buffers without doubling memory during lag compensation.
- Time
- O(n)
- Space
- O(1)
function reverseList(head) {
let prev = null, curr = head;
while (curr) {
const next = curr.next;
curr.next = prev;
prev = curr;
curr = next;
}
return prev;
}Tradeoff:
Riot Games-specific tips
Riot wants in-place reversal traced on a whiteboard with named pointers — the same discipline that keeps replay-buffer reversal allocation-free under their 30Hz server tick rate.
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 Riot Games interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.
Practice these live with InterviewChamp.AI →