Given a permutation of numbers stored in an array nums,
generate the next permutation sequence that is lexicographically greater than the current one.
If no such permutation exists, rearrange it to become the lowest sequence (ascending order).
The algorithm must modify the array in-place with constant space complexity.
Input: nums = [1,5,8,4,7,6,5,3,1]
Output: [1,5,8,5,1,3,4,6,7]
Input: nums = [1,3,2]
Output: [2,1,3]
Input: nums = [2,3,1]
Output: [3,1,2]
Accepted:
Submission: