Problem · Array

Next Permutation

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem statement

Return the lexicographically next permutation of nums. If the current ordering is the greatest possible, return the smallest ordering. Duplicate values are allowed.

Function

nextPermutation(nums: int[]) → int[]

Examples

Example 1

nums = [1,2,3]return = [1,3,2]

Swapping the final two values gives the next greater ordering.

Constraints

  • 1 <= nums.length <= 10000
  • Values fit in a signed 32-bit integer.

More Atlassian problems

drafts saved locally
public int[] nextPermutation(int[] nums) {
  // Write your code here.
}
nums[1,2,3]
expected[1,3,2]
checking account