Reverse the Delivery Stops Between Two Positions on a Route
Last updated: November 29, 2026
Quick Overview
A delivery route is a singly linked list of stops. Given positions left and right (1-indexed, left <= right), reverse only the stops from left to right in place and return the head.
Amazon
November 29, 20260
0
0 solved
A delivery route is a singly linked list of stops. Given positions left and right (1-indexed, left <= right), reverse only the stops from left to right in place and return the head.
Amazon Logistics engineers often frame list manipulation as route edits, such as a driver flipping a segment of stops. The interviewer looks for a single pass, correct reconnection of both boundaries, and no off-by-one bugs.
What the Interviewer Expects
- Use a dummy node so left = 1 needs no special case
- Walk to the node just before position left
- Reverse the sublist with head insertion in one pass
- Reconnect both ends correctly
- Trace an example aloud before coding
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
- What if left and right are stop IDs rather than positions?
- Can you reverse every alternate segment of length k?
- How would you support many such reversals on a very long route efficiently?
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 of a singly linked list of stops and integers left and right with 1 <= left <= right <= n. Output: the same list with the stops at positions left through right reversed, everything els...
High-Level Design
Add a dummy before the head and advance a pointer pre left minus 1 steps so it sits just before the segment. Let tail be the first node of the segment; after reversal it becomes the segment's last...