Find the next lexicographical permutation of an array. If no next permutation exists (array is in descending order), return the array sorted in ascending order.
Examples
const nums =[1,2,3];nextPermutation(nums);console.log(nums);// [1, 3, 2]const nums2 =[3,2,1];nextPermutation(nums2);console.log(nums2);// [1, 2, 3] (wrap around to first)
Constraints
Modify the array in-place (O(1) extra space)
1 <= nums.length <= 100
0 <= nums[i] <= 100
If no next permutation exists, return the first permutation