Practice Next Permutation
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
A permutation of an array of integers is an arrangement of its members into a sequence or linear order. The next permutation of an array of integers is the next lexicographically greater permutation of its integer. More formally, if all the permutations of the array are sorted in one container according to their lexicographical order, then the next permutation of that array is the permutation that follows it in the sorted container. If such arrangement is not possible, the array must be rearranged as the lowest possible order (i.e., sorted in ascending order). Given an array of integers nums, find the next permutation of nums. The replacement must be in place and use only constant extra memory.
Source: Next Permutation on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
nums = [1,2,3]
[1,3,2]
# Example 2
nums = [3,2,1]
[1,2,3]
# Example 3
nums = [1,1,5]
[1,5,1]
Constraints
Related LeetCode Problems
Practice more problems similar to Next Permutation.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.