Implement the next permutation, which rearranges numbers into the numerically next greater permutation of numbers for a given array A of size N.
If such arrangement is not possible, it must be rearranged as the lowest possible order i.e., sorted in an ascending order.
The test cases of this problem include :
Input :
A = [20, 50, 113]
Output :
[20, 113, 50]
How is [20, 113, 50] greater than [20, 50, 113]?
Similarly ,
Input :
A = [5, 18, 9]
Output :
[9, 5, 18]
How is this next permutation rather than [5,9,18]?