65. Reverse Linked List II
mediumAsked at VercelReverse a sublist of a linked list between positions left and right in one pass. Vercel asks this for the in-place sublist surgery — same pointer-juggling discipline they need to reorder middleware stages.
By Alex Chen, Founder, InterviewChamp.AI · Last verified
Source citations
Public interview reports confirming this problem appears in Vercel loops.
- Glassdoor (2025-Q4)— Vercel platform onsite; one-pass expected.
- Blind (2026-Q1)— Listed in Vercel screen pool.
Problem
Given the head of a singly linked list and two integers left and right where left <= right, reverse the nodes of the list from position left to position right, and return the reversed list.
Constraints
The number of nodes in the list is n.1 <= n <= 500-500 <= Node.val <= 5001 <= left <= right <= n
Examples
Example 1
head = [1,2,3,4,5], left = 2, right = 4[1,4,3,2,5]Example 2
head = [5], left = 1, right = 1[5]Approaches
1. Extract, reverse, splice back
Split into three lists: prefix, middle, suffix. Reverse middle. Stitch.
- Time
- O(n)
- Space
- O(1)
// Verbose; one-pass version is cleaner.Tradeoff: Works but allocates multiple cursors.
2. One-pass head-insertion (optimal)
Dummy head. Walk to position left-1. Then repeatedly take the node after current and insert it at the front of the reversed-so-far sublist.
- Time
- O(n)
- Space
- O(1)
function reverseBetween(head, left, right) {
const dummy = { val: 0, next: head };
let prev = dummy;
for (let i = 1; i < left; i++) prev = prev.next;
// prev now points to node at position left-1
let cur = prev.next;
for (let i = 0; i < right - left; i++) {
const move = cur.next;
cur.next = move.next;
move.next = prev.next;
prev.next = move;
}
return dummy.next;
}Tradeoff: Single pass. The head-insertion trick reverses the sublist by repeatedly taking the next node and inserting it at the start of the reversed portion. Three pointer updates per step.
Vercel-specific tips
Vercel grades the one-pass head-insertion. Bonus signal: drawing the three pointer states on the whiteboard (move, move.next, prev.next) before coding. Mention the dummy head's role in handling left=1.
Common mistakes
- Iterating left-1 times instead of left times — off-by-one for prev.
- Wrong order of the three pointer updates — breaks the chain.
- Forgetting the dummy — left=1 becomes a special case.
Follow-up questions
An interviewer at Vercel may pivot to one of these next:
- Reverse Linked List (LC 206) — the full reversal.
- Reverse Nodes in k-Group (LC 25, hard) — apply this pattern in chunks.
- What if right > list length? Bounds-check.
Solve it now
Free. No sign-up. Python and JavaScript run instantly in your browser.
FAQ
Why head-insertion?
It avoids the explicit three-pointer (prev, cur, next) dance that reverses an entire list. By repeatedly taking the node AFTER current and moving it to the FRONT of the reversed portion, the sublist reverses naturally in place.
Why a dummy head?
If left == 1, the head itself is part of the reversed segment. Without dummy, prev has nowhere safe to anchor.
Practice these live with InterviewChamp.AI
Drill Reverse Linked List II 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 →