Reverse Only a Window of Positions in a Linked Changelog

Last updated: November 29, 2026

Quick Overview

Reverse the nodes from position left to position right (1-indexed, inclusive) of a singly linked changelog in one pass, leaving the rest of the list untouched.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Medium

0

0

0 solved


Reverse the nodes from position left to position right (1-indexed, inclusive) of a singly linked changelog in one pass, leaving the rest of the list untouched.

A Google onsite pointer problem that checks whether you can reverse a sublist while reconnecting both boundaries correctly. Interviewers look for the head-insertion technique and a dummy node for left = 1.

What the Interviewer Expects
  • Use a dummy so left = 1 needs no special case
  • Walk to the node just before left
  • Reverse by repeatedly moving the next node to the front of the window
  • Keep both boundary connections correct
  • One pass, O(1) space
Key Topics to Cover
linked list
sublist reversal
sentinel node
head insertion
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Reverse several disjoint windows given as a list of ranges.
  • Reverse every other window of size k.
  • Do it on a doubly linked list.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: head, 1 <= left <= right <= n.
  • Output: head with positions left..right reversed.
  • One pass, O(1) extra space....
High-Level Design

Find before, the node at position left - 1 (the dummy if left is 1). Let start = before.next; it will end up as the last node of the reversed window. Then repeat right - left times: take the node ...


Submit Your Answer
Markdown supported