/90. Subsets II

90. Subsets II

Medium
Arrays61% acceptance

Given an integer array input_array that may contain duplicate values, return all possible subsets (the power set) of input_array. The returned list must not contain duplicate subsets. The order of subsets in the output does not matter.

Example 1

Input: [3, 3, 1]

Output: [[], [1], [3], [1, 3], [3, 3], [1, 3, 3]]

Explanation: All unique subsets are listed, avoiding duplicates.

Example 2

Input: [-1, 0, 0]

Output: [[], [-1], [0], [-1, 0], [0, 0], [-1, 0, 0]]

Explanation: Subsets with duplicate zeros are included only once.

Constraints

  • 1 <= len(input_array) <= 10
  • -10 <= input_array[i] <= 10
Python (current runtime)

Case 1

Input: [2, 2, 2]

Expected: [[], [2], [2, 2], [2, 2, 2]]

Case 2

Input: [1, -1, -1]

Expected: [[], [1], [-1], [1, -1], [-1, -1], [1, -1, -1]]

Case 3

Input: [4]

Expected: [[], [4]]

Case 4

Input: [0, 1, 1]

Expected: [[], [0], [1], [0, 1], [1, 1], [0, 1, 1]]