Reported July 2026
Amazonmath

Permutation Sorter

Reported by candidates from Amazon's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.

Get StealthCoderRuns invisibly during the live Amazon OA. Under 2s to a working solution.
Founder's read

The mistake that sinks a first attempt at Amazon's Permutation Sorter, reported in July 2026, is reaching for BFS over all arrangements when the answer is a cyclic-shift count. You get a permutation of 1..n and two moves: reverse the whole thing, or rotate left by one. It's guaranteed solvable, so the structure is tight. The array is always some rotation of the sorted order or some rotation of the reversed order. If you blank on how to count the moves under the clock, StealthCoder runs invisibly during the live assessment and gives you the solution as a safety net.

The problem

Amazon engineers are testing a new tool, the Permutation Sorter, built to reorder sequences using limited operations.
Given a permutation of integers, the objective is to sort the permutation using only two specific operations:
Reverse the entire permutation.
Transfer the first element of the permutation to the last position, i.e., change arr[0], arr[1],..., arr[n-1] to arr[1], arr[2],..., arr[n-1], arr[0].
Formally, given a permutation arr of size n, determine the minimum number of operations needed to sort the given permutation in increasing order. The permutation provided is guaranteed to be sorted using only these two operations.
Note: A permutation of length n is a sequence of integers from 1 to n containing each number exactly once.
Complete the function findMinimumOperations in the editor below.

Function
findMinimumOperations(arr: int[]) → int

Examples
Example 1
arr = [2, 3, 4, 5, 6, 7, 8, 9, 10, 1]
return = 3
For n = 10, the permutation can be sorted by performing the following operations:
Reverse the permutation to get arr = [1, 10, 9, 8, 7, 6, 5, 4, 3, 2].
Transfer the first element to the last position to get arr = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1].
Reverse the permutation to get arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10].
It can be shown that the given permutation can only be sorted using a minimum of 3 operations.

Reported by candidates. Source: FastPrep

Pattern and pitfall

Think of the array as a circle. Rotation keeps the circular order. Reversal flips it. So the sorted target is reachable only if the array is a rotation of 1..n or a rotation of n..1. Find where 1 sits and count the rotations needed to bring it to the front. Do that for the original array and for the reversed one, then add one for the reverse move where needed. Also handle the case where the array is reversed-sorted, which can cost one reverse and no rotations. The common pitfall is forgetting that a reverse can come before or after rotating, and that rotating left k times equals rotating right n-k times in the reversed view. Compute every option, take the minimum, and test against the example, which gives 3. If the case analysis gets tangled live, StealthCoder is the hedge that hands you the working code. Complexity is O(n) time and O(1) extra space.

If this hits your live OA and you blank, StealthCoder solves it in seconds, invisible to the proctor.

If this hits your live OA

You can drill Permutation Sorter cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it.

Get StealthCoder

Related leaked OAs

⏵ The honest play

You've seen the question. Make sure you actually pass Amazon's OA.

Amazon reuses patterns across OAs. Built by an Amazon engineer who would have shipped this the night before his JPMorgan OA if he'd had it. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Permutation Sorter FAQ

What's the trick in Amazon's Permutation Sorter?+

Treat the array as a circular sequence. Both operations preserve circular adjacency, with reverse flipping direction. So you never simulate. You locate where 1 sits, count the rotations to bring it to the front, and compare a few fixed move sequences that include zero, one or two reverses.

Do I need BFS for this problem?+

No. BFS over states would blow up for large n. The guarantee that the array is sortable means it's a rotation of sorted or reversed-sorted order. That lets you compute the answer directly in O(n) with a position lookup and a few candidate counts.

What's the most common mistake on this one?+

Counting only rotations and ignoring the reverse, or counting one reverse when the example needs two. In the sample, reverse, rotate, reverse gives 3 moves. Enumerate candidates with reverses at the start and end instead of assuming a single order.

How do I check my solution before submitting?+

Run the sample [2,3,...,10,1] and confirm 3. Then try an already sorted array, which should return 0, and a fully reversed array, which should return 1. Add a small case like n=2 or n=3 by hand. Those edge cases catch most off-by-one rotation errors.

How do I prepare for this in 48 hours?+

Practice circular-array reasoning: rotations, finding a pivot index, and modular arithmetic. Write the candidate-minimum approach on two or three small arrays by hand. You don't need a full study plan. You need to recognize that the operations define a tiny set of reachable states.

Problem reported by candidates from a real Online Assessment. Sourced from a publicly-available candidate-aggregated repository. Not affiliated with Amazon.

OA at Amazon?
Invisible during screen share
Get it