FunctionRacerProblemsRace

Next Permutation

MediumArraysPython, JavaScript, TypeScript, Java, C++

List all the orderings of the items of nums from smallest to largest, comparing them like words in a dictionary (first item first). Change nums in place into the ordering that comes right after the current one.

If nums is already the last ordering, change it into the first one (sorted increasing). Repeated values are allowed. Return nothing.

Example 1

nums [1,2,3]
returns [1,3,2]

The next ordering is [1, 3, 2].

Example 2

nums [3,2,1]
returns [1,2,3]

Last ordering, so wrap around to [1, 2, 3].

Constraints

Race itor take your time

Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.

More Arrays problems