nums
containing numbers from 1 to n
.(n - 1)!
and store them in an array.k
by 1 to fit into the range from 0 to n! - 1
.(n - 1)!
down to 1!
:
a. Determine the index for the current base by dividing k
by the factorial value.
b. Select the element at this index from nums
and append it to the result.
c. Remove the selected element from nums
.
d. Update k
to be the remainder of the division.nums
to the result.