FastPrepPermutations

Permutations

Bloomberg LP logoBloomberg LP● MediumNEW GRADPHONE SCREENONSITE INTERVIEW
Learn

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 Bloomberg LP problems

See Bloomberg LP hiring insights
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…