Design an algorithm that accepts as input a given permutation of the ten digits and returns as output the next permutation in the set in lexical order. As an example, if we have:
Current permutation is: 7 9 0 1 6 3 8 5 4 2
Then the next permutation is: 7 9 0 1 6 4 2 3 5 8
As a hint, note that the last four digits in the current permutation are in descending order