This question evaluates understanding of permutations and lexicographic ordering, in-place array manipulation, and algorithmic reasoning about time and space constraints, including handling duplicates and edge cases.
Given an integer array nums representing a permutation of its elements, modify the array in-place to produce the next lexicographically greater permutation.
nums
into that next greater ordering.
nums
is in non-increasing order), rearrange
nums
into the
lowest possible order
(sorted ascending).
nums
: an array of integers (may contain duplicates).
nums
in-place.
nums = [1,2,3]
→ after update:
[1,3,2]
nums = [3,2,1]
→ after update:
[1,2,3]
nums = [1,1,5]
→ after update:
[1,5,1]
n
can be 0, 1, or larger.
[2,2,1]
).