Next Permutation

Advanced

Let's help our Python explorer friends generate the next permutation of a sequence of numbers!

A permutation is an arrangement of numbers. For example, the numbers [1, 2, 3] can be permutated to form this list: [1, 2, 3], [1, 3, 2], [2, 1, 3], [2, 3, 1], [3, 1, 2], and [3, 2, 1].

The task is to develop a function that, given a list of numbers that represents a permutation, will return the next permutation of numbers in lexicographical order. If the given permutation is the highest possible, the function should return the lowest permutation.

For example:

next_permutation([1, 2, 3]) # Returns: [1, 3, 2] next_permutation([3, 2, 1]) # Returns: [1, 2, 3] # Reset to the lowest permutation next_permutation([1, 1, 5]) # Returns: [1, 5, 1]

Let's put on our coding cap and create this function next_permutation that outputs the exciting world of the next permutation!

Geek
Inputs

Arg 1:

[1,2,3]
Expected Output
[1, 3, 2]
Actual Output
Next Permutation [advanced] | Coding for Kids