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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

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
linked lists
in-place reversal
dummy node
pointer manipulation
route editing
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
  • 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 Problems
Sample 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...


Submit Your Answer
Markdown supported