Meta interview question

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