Reported June 2024
Amazonmath

Find K Level Permutation

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

Amazon's June OA included a permutation problem that looks straightforward until you hit the time limit. You're given a number k and asked to find the kth lexicographic permutation of a sequence, usually 1 to n. Most candidates try brute force (generate all permutations), which times out instantly. The trick is binary search combined with factorial math to skip huge blocks of permutations without generating them. StealthCoder handles the factorial indexing logic if you blank on the formula during the live assessment.

Pattern and pitfall

The pattern here is factorial number system decomposition, not traditional binary search. You don't binary search the answer space. Instead, you use factorials as place values. For a permutation of length n, there are n! total arrangements. Each position in the result can be filled by n choices, and once you pick one element, the remaining n-1 positions have (n-1)! arrangements. You calculate which element belongs in each position by dividing k by the factorial of the remaining length. The candidate trap is overthinking the 'binary search' framing and trying to search a range instead of systematically indexing into the factorial-weighted tree of permutations. StealthCoder knows this is a decomposition problem disguised as a search problem and will flag the correct factorial index pattern when you're live.

The honest play: practice the pattern, and have StealthCoder ready for the one you didn't see coming.

If this hits your live OA

You can drill Find K Level Permutation 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 for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play.

Get StealthCoder

Related leaked OAs

⏵ Practice the LeetCode equivalent

This OA pattern shows up on LeetCode as permutation sequence. If you have time before the OA, drill that.

⏵ The honest play

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

Amazon reuses patterns across OAs. Built for the candidate who saw this exact problem leak two days before his OA and wondered if anyone had a play. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Find K Level Permutation FAQ

Is this really a binary search problem?+

Not in the classical sense. The hint is misleading. You're using factorial decomposition to directly index into permutations, not searching a range. Think of it as digit extraction in base-factorial, not a binary search over candidates.

What's the time complexity I need?+

O(n^2) due to the permutation list removal or swapping logic. That's fast enough. Brute force O(n!) will timeout. The factorial decomposition gets you from exponential to polynomial instantly.

How do I handle 1-indexed vs 0-indexed k?+

Check the problem statement carefully. Most OAs use 1-indexed k (first permutation is k=1). Adjust your modulo and division logic accordingly. Off-by-one errors here are common.

Should I precompute factorials?+

Yes. Build a factorial array up to n before the main loop. It's a one-liner and saves repeated computation. Without it, you're wasting cycles in the tight loop.

Will Amazon ask a follow-up about efficiency?+

Possibly. Know that O(n^2) with a list is acceptable, but O(n log n) using a balanced BST (or O(n) with a Fenwick tree for serious candidates) is faster. Mention it if you have time, but solve the core problem first.

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