Code Golf

Sorted Order of ArraysNow to start thinking laterally! For an array of N distinct numbers in increasing order, there are N! ways to permute that array. Those permuted arrays can then also be sorted, prioritizing whichever array has the smallest element in the first position, then breaking ties with the second position, etc. The input is an array and a number M with 0 <= M < N! , and the output should be, if one sorted all N! permutations of the original array, the Mth element of that list of permutations. So, M = 0 would give your original sorted array, and M=N!-1 would be the array in reverse. | Input | Output | |-------|--------| |[1, 2, 3, 4], 5|[1, 4, 3, 2]| |[1, 4, 7], 2|[4, 1, 7]| |[3, 4, 6, 9, 10], 114|[10, 9, 3, 4, 6]| |[1, 2, 3], 0|[1, 2, 3]|