Loading problem…
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.
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)