AO
Back

Maximize Shipment Order: Sort One Window

Also reported as Sort Packages Within a Window

OAAsync OALast reported October 2026Low Frequency

Problem Overview

The round: the coding half of Amazon's online assessment (40 minutes in one report), next to an AI-assisted debugging task. Two candidates reported it, on September 30 and October 9, 2026. The second posted the full prompt, "Maximize Shipment Order"; the first describes the same task and calls it a hard DP problem. The example and constraints below are as reported; the prose is paraphrased.

Problem

shipmentOrder is a permutation of 1..n and windowSize is an integer. You must apply this operation exactly once: choose a start i with 1 ≤ i ≤ n - windowSize + 1 (1-based) and sort the windowSize shipments from position i to i + windowSize - 1 in ascending order, leaving every other position as it is. Return the lexicographically largest order you can end up with. (Array A is lexicographically larger than B if, at the first index where they differ, A has the larger value.)

The operation is mandatory, but choosing a window that is already sorted leaves the array unchanged, and that is the right choice when sorting any other window would make the order smaller.

def maximizeShipmentOrder(shipmentOrder: list[int], windowSize: int) -> list[int]: ...

Constraints

  • 1 ≤ windowSize ≤ n ≤ 2 * 10^5
  • shipmentOrder is a permutation of the integers 1 to n.

Example

shipmentOrder = [5, 1, 4, 3, 2], windowSize = 3

i = 1: sort [5, 1, 4] -> [1, 4, 5, 3, 2]
i = 2: sort [1, 4, 3] -> [5, 1, 3, 4, 2]
i = 3: sort [4, 3, 2] -> [5, 1, 2, 3, 4]

Output: [5, 1, 3, 4, 2]

What Reports Emphasize

What candidates report: The full prompt was posted in October 2026. A candidate nine days earlier calls it a hard DP problem and says they solved it smoothly only because they had seen it before.

Our note (not from the reports): Sorting a window never makes the order larger. If some window is already sorted, return the input unchanged; otherwise choose the window whose first changed position is furthest right, and the earliest such window on a tie.

Practice

Write your own against 6 test cases, or read the worked solution — approach, complexity, and code that runs.

Prepping for Amazon with friends?

Send them this page. It is free to read, no account needed.

More Amazon Questions

Free preview

Every question in the Amazon catalog gets this depth

What you just read — canonical solution, follow-up arc, what passing candidates actually did — exists for all 57 Amazon questions, refreshed monthly from new candidate reports.

$59/mo — or $50/mo with the 3-month pass · cancel anytime
Amazon · OA · Reported 2× across candidate reports
Is this helpful?