Skip to main content

66. Reverse Linked List II

mediumAsked at Plaid

Reverse a sublist of a linked list between positions left and right. Plaid asks this as a pointer-juggling problem — exactly the shape they use when restoring a corrupted segment of a transaction-history list from a backup.

By Alex Chen, Founder, InterviewChamp.AI · Last verified

Source citations

Public interview reports confirming this problem appears in Plaid loops.

  • LeetCode Discuss (2026)Plaid SWE II OA.
  • Glassdoor (2025)Plaid backend onsite.

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 <= 500
  • 1 <= left <= right <= n

Examples

Example 1

Input
head = [1,2,3,4,5], left = 2, right = 4
Output
[1,4,3,2,5]

Example 2

Input
head = [5], left = 1, right = 1
Output
[5]

Approaches

1. Collect, reverse middle, rebuild

Dump into array, reverse the middle slice, rebuild a new list.

Time
O(n)
Space
O(n)
// Allocates a new list.

Tradeoff: Works but ignores in-place opportunity.

2. In-place head-insertion within window

Walk to position left-1 (call it prev). Then for each of the next (right-left) iterations, take prev.next.next and insert it just after prev. This reverses the window by repeated head-insertion.

Time
O(n)
Space
O(1)
function reverseBetween(head, left, right) {
  const dummy = { next: head };
  let prev = dummy;
  for (let i = 1; i < left; i++) prev = prev.next;
  let curr = prev.next;
  for (let i = 0; i < right - left; i++) {
    const moved = curr.next;
    curr.next = moved.next;
    moved.next = prev.next;
    prev.next = moved;
  }
  return dummy.next;
}

Tradeoff: In-place. The head-insertion idiom is the cleanest way to reverse a sublist without losing track of boundaries.

Plaid-specific tips

Plaid grades this on the dummy-head + walk-to-prev pattern. Bonus signal: count out loud the number of swaps (right - left) — that's how many insertions happen. Connect to restoring a corrupted sub-segment of a transaction list from a chronologically-reversed backup feed.

Common mistakes

  • Walking to position 'left' instead of 'left-1' — misses the prev anchor.
  • Performing right - left + 1 iterations instead of right - left — extra iteration overshoots.
  • Forgetting the dummy head — left=1 case breaks.

Follow-up questions

An interviewer at Plaid may pivot to one of these next:

  • Reverse in k-groups (LC 25).
  • Reverse a doubly-linked list sublist.
  • Reverse based on a predicate, not position.

Solve it now

Free. No sign-up. Python and JavaScript run instantly in your browser.

Output

Press Run or Cmd+Enter to execute

FAQ

Why head-insertion?

Each iteration moves one node from 'just after current' to 'just after prev,' which is equivalent to pushing it onto a stack and then popping. After all iterations, the window is reversed.

Why dummy head?

When left == 1, prev is the head, and we'd need a separate code path to update head. Dummy head eliminates that special case.

Practice these live with InterviewChamp.AI

Drill Reverse Linked List II and other Plaid interview questions under real-loop conditions with instant feedback on your reasoning, complexity claims, and code.

Practice these live with InterviewChamp.AI →