/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) without duplicate subsets. Each subset must be represented as a list of integers. 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: [2]

Output: [[], [2]]

Explanation: Single element yields two subsets: empty and itself.

Constraints

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

Case 1

Input: [1,1,2]

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

Case 2

Input: [-1,0,0]

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

Case 3

Input: [4,4,4]

Expected: [[], [4], [4,4], [4,4,4]]

Case 4

Input: [5,6]

Expected: [[], [5], [6], [5,6]]