LeetCode MEDIUM 31 Next Permutation Summary
Generated by Codex with GPT-5
Quick facts
- Difficulty:
MEDIUM - Problem: Next Permutation
- Main tags:
Array,Two Pointers
What the problem is really asking
The array represents one permutation of the numbers.
The task is to mutate it into the very next permutation in lexicographic order, which means:
- make the number just a little larger
- keep that increase as small as possible
- do everything in place
If the current permutation is already the largest possible one, such as [3, 2, 1], then there is no larger answer. In that case, the correct result is the smallest permutation, which is ascending order.