FastPrepPermutations

Permutations

EPAM logoEPAM● MediumFULLTIMEPHONE SCREEN
Learn

Problem statement

Given an array nums of distinct integers, return every permutation of its values.

For deterministic judging, return the 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]]

Three distinct values have 3! = 6 permutations.

Example 2

nums = [0,1]return = [[0,1],[1,0]]

Two values have two possible orders.

Constraints

  • 1 <= nums.length <= 8.
  • Every value is distinct and in [-10, 10].

Source note: Author-written prompt excerpt retained for source fidelity.

More EPAM problems

See EPAM 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…