As reported: Morgan Stanley Associate (4 years of experience, big data team), Jul 2025. Round 1: a discussion of the projects on the resume, then the next permutation of an array, then the low-level design of Snake and Ladder.
Rearrange nums into the next lexicographically greater permutation of its values. If no greater permutation exists (the array is in descending order), rearrange it into the lowest order (ascending). Do it in place with O(1) extra memory.
This is LeetCode 31 — Next Permutation.
Example 1
nums = [1,2,3] -> [1,3,2]
Example 2
nums = [3,2,1] -> [1,2,3]
Example 3
nums = [1,1,5] -> [1,5,1]
Constraints: 1 ≤ nums.length ≤ 100; 0 ≤ nums[i] ≤ 100.
Code runner format: one JSON value per line: nums (LeetCode's test-case format). Implement nextPermutation(nums), modifying nums in place; the harness prints nums afterwards.