Maximize Shipment Order by Sorting One Window
Updated
Problem statement
shipmentOrder has length n and is a permutation of 1..n. Choose exactly one contiguous window of length windowSize, sort that window in ascending order, and return the lexicographically largest complete array obtainable.
Positions are 1-based. A window that starts at position i covers positions i through i + windowSize - 1, so 1 <= i <= n - windowSize + 1.
One array is lexicographically larger than another array of the same length when it has the larger value at the first position where the two differ.
Examples
Example 1
shipmentOrder = [5,1,4,3,2]windowSize = 3return = [5,1,3,4,2]With 1-based positions there are three windows of length 3. Starting at i = 1 gives [1,4,5,3,2], starting at i = 2 gives [5,1,3,4,2], and starting at i = 3 gives [5,1,2,3,4]. The window that starts at i = 2 (positions 2 through 4) keeps 5, 1 at the front and then has the larger third value, so it is the answer.
Unlock this recently reported problem
FastPrep Pro gives you full access to interview problems reported within the last week.
- Full problem statement and constraints
- 1 more worked example, explained
- Guided hints and editorial
- Run your code on real test cases
$99 billed yearly — or $19 month-to-month. Cancel anytime.
More Amazon Online Assessment questions
- Lexicographically Largest IdentifierOA · Seen Nov 2026
- Top K Frequent ElementsOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Fill One Exact-Length Binary WindowOA · Seen Nov 2026
- Minimum Grid InconvenienceOA · Seen Nov 2026
- Maximize K-Element AND with an Increment BudgetOA · Seen Nov 2026
- Task SchedulerOA · PHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Get Smallest Base SegmentOA · Seen Nov 2026
- Minimum Cost of Left and Right PropagationOA · Seen Nov 2026
- Maximum Equal-Bit Pairs in a SubsequenceOA · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Most Segments That Sort the ArrayRippling · OARippling interview questions
- Most Items Within Budget from a Start IndexHudson River Trading · OAHudson River Trading interview questions
- Power Update After K-th Largest InsertionGoogle · OAGoogle interview questions
- Alternating Jumps to the Last IndexExpedia · OAExpedia interview questions
- Count Decreasing TripletsAirbnb · OAAirbnb interview questions
- Rebuild the Queue From Taller-in-Front CountsAdobe · PHONE SCREENAdobe interview questions
- Implement QuicksortJP Morgan Chase · ONSITE INTERVIEWJP Morgan Chase interview questions
- Hard Disk Clustering CostConfluent · OAConfluent interview questions
- Sliding Window MedianAuxoAI · OA
- Delete and Freeze GameRubrik · OARubrik interview questions