Problem · Array

Permutations

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem statement

Given an array of distinct integers, return every possible ordering of its values.

Return the list of permutations in lexicographic order.

Function

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

Examples

Example 1

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

Every one of the six orderings appears exactly once.

Constraints

  • 1 <= nums.length <= 8
  • -10^9 <= nums[i] <= 10^9
  • All values are distinct.

More Atlassian problems

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