The Next Lexicographic Arrangement

A lock displays a sequence of digits. Its current display is an array nums containing a permutation, possibly with repeated values. Rearrange the same elements in place so the display becomes the smallest sequence strictly larger in lexicographic order than the current sequence.

If no larger arrangement exists, rearrange the display into its smallest possible order. Return the resulting array.

The output must use exactly the original elements. Equal values are allowed, and the rearrangement must use only constant extra space apart from the input array.

Examples
Input: [1]
Output: [1]
Hints
Related Problems

The Next Lexicographic Arrangement

A lock displays a sequence of digits. Its current display is an array `nums` containing a permutation, possibly with repeated values. Rearrange the same elements **in place** so the display becomes the smallest sequence strictly larger in lexicographic order than the current sequence.