Kth Order of the Numbers
Write the numbers 1 to n in every possible order, and sort those orders the way a dictionary sorts words, comparing number by number. Return the k-th order as a list, counting from 1.
For n = 3 the orders are [1,2,3], [1,3,2], [2,1,3], [2,3,1], [3,1,2], [3,2,1].
Example 1
n 3
k 4
returns [2,3,1]
The fourth order in the list above.
Constraints
1 <= n <= 121 <= k <= n!
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.