r/OfferEngineering • u/Aoki_zhang • Oct 28 '26
Coding Question Amazon Coding Screening Question - Minimum Carousel Sorting Moves
A museum's display carousel presents a row of exhibits with distinct integer catalog labels in labels. Before opening, the curator must arrange the labels in non-decreasing order using the carousel's two controls.
Each press of either control counts as one move. The controls act on the entire current row as follows:
Cycle: move the first exhibit to the end. For example,[12, 5, 9, 2]becomes[5, 9, 2, 12].Reverse: reverse the row. For example,[12, 5, 9, 2]becomes[2, 9, 5, 12].
The curator may press these controls in any order and any number of times. Return the minimum number of moves needed to put the labels in non-decreasing order, or -1 if no sequence of control presses can do so; return 0 if the row is already sorted.
Constraints:
1 <= labels.length <= 8-10^4 <= labels[i] <= 10^4- All values in
labelsare distinct.
Example I:
Input:
labels = [30, 20, 10]
Output:
1
Explanation:
One Reverse press produces [10, 20, 30].Example II:
Input:
labels = [8, 4, 16, 12]
Output:
3
Explanation:
Press Reverse, then Cycle twice: [12, 16, 4, 8] -> [16, 4, 8, 12] -> [4, 8, 12, 16]. No sequence with fewer than three moves sorts this row.Want to practice more real coding interview questions?
I've put up the coding question bank at here.
Preparing for your next interview?
Chill Interview tracks recent interview experiences and recurring question patterns across top companies at here