Meta Interview Question

Make a function that creates the previous permutation for a given number O(n) time