Given an array, rearrange its elements into the next numerically greater permutation.
If such permutation is not possible, it must rearranged as the lowest possible order (sorted in an ascending order).
The solution has to be implemented using constant space
Do not use "next permutation" methods from standard libraries.
Input: [1, 2, 3]
Output: [1, 3, 2]
Input: [1, 3, 2]
Output: [2, 1, 3]
Input: [3, 2, 1]
Output: [1, 2, 3]
The sequence 3, 2, 1
has no numerically greater permutation, so we return the lowest permutation possible.
Input: [1, 1, 5]
Output: [1, 5, 1]
Input: [20, 50, 113]
Output: [20, 113, 50]
Solution coming up... :)