 All Problems
Next Permutation
medium
arrays
two pointers
amazon
google
microsoft
facebook

Rearrange nums into the lexicographically next greater permutation. If no next permutation exists (descending order), rearrange to the lowest order (ascending). Must be in-place.

Example 1:

Input:  1 2 3
Output: 1 3 2

Example 2:

Input:  3 2 1
Output: 1 2 3

Input format: Space-separated integers.

Output format: Space-separated integers.

Run to check your code against the sample cases, or submit to run every case