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.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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 ...