Permutations II

Given an array nums that may contain duplicate values, return every distinct permutation of it. The permutations can be returned in any order.

30:00

Permutations II
medium
Free written solution
Topics
Companies

Given an array nums that may contain duplicate values, return every distinct permutation of it. The permutations can be returned in any order.

Example 1:
Input: {"nums":[1,1,2]}
Output: [[1,1,2],[1,2,1],[2,1,1]]
Constraints:
  • 1≤nums.length≤81 \leq \text{nums.length} \leq 8

  • −10≤nums[i]≤10-10 \leq \text{nums}[i] \leq 10

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"nums":[1,1,2]}

nums = [1,1,2]. Equal values are interchangeable, so the goal is each distinct ordering exactly once.

Input

1

i=0

1

i=1

2

i=2

Path being built

1

2

3

Distinct permutations

found: 0

none yet

Variables
VariableValue
nums[1,1,2]
DepthFunction Call
Stack empty
0/32