Permutation Sequence
Real-world version: Nozzle Firing BookThe statement here is our own: the same inputs, outputs and technique.
A calibration rig drives n nozzles, numbered 1 through n. Its test book holds every firing order of those nozzles exactly once, one order per line, each written as the nozzle numbers run together with nothing between them.
Every line of the book has the same number of digits, and the book is sorted by reading each line as a number and placing smaller numbers earlier. With n = 3 the book runs 123, then 132, then 213, then 231, then 312, and finally 321.
Given n and a line number k, with the opening line counted as line 1, return that line of the book as a string.
Examples
Example 1
- Input
- n = 4, k = 7
- Output
- "2134"
Line 7 of the four-nozzle book reads 2134, which fires each of the nozzles 1, 2, 3 and 4 once.
Example 2
- Input
- n = 5, k = 13
- Output
- "14235"
Line 13 of the five-nozzle book reads 14235, and every nozzle from 1 to 5 appears in it exactly once.
Example 3
- Input
- n = 1, k = 1
- Output
- "1"
One nozzle admits one firing order, so the book has the single line 1.
Constraints
- 1 <= n <= 9
- 1 <= k <= n!
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def firing_order(n: int, k: int) -> str:public String firingOrder(int n, int k)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 12 test cases: 12 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's