Permutation Sequence
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
Write the digits 1 through n in every possible order and sort the resulting strings lexicographically, giving n! strings. Return the k-th string in that sorted list (1-indexed).
The input satisfies 1 <= k <= n!, so the answer always exists. Return the permutation as a string of digits with no separators.
Aim to build the answer digit by digit in O(n^2) time instead of generating permutations one after another.
Examples
Constraints
- 1 <= n <= 9
- 1 <= k <= n!
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.