/78. Subsets

78. Subsets

Medium
Arrays82.1% acceptance

Given an integer array input_array containing unique elements, return a list of all possible subsets (the power set) of input_array. Each subset should be represented as a list, and the solution should not contain duplicate subsets. The order of subsets in the output does not matter.

Example 1

Input: [4, 5]

Output: [[], [4], [5], [4, 5]]

Explanation: All possible subsets of [4, 5] are listed.

Example 2

Input: [-2, 0, 2]

Output: [[], [-2], [0], [-2, 0], [2], [-2, 2], [0, 2], [-2, 0, 2]]

Explanation: All possible subsets of [-2, 0, 2] are listed.

Constraints

  • 1 <= len(input_array) <= 10
  • -10 <= input_array[i] <= 10
  • All elements in input_array are unique
Python (current runtime)

Case 1

Input: [7]

Expected: [[], [7]]

Case 2

Input: [-1, 1]

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

Case 3

Input: [3, 6, 9]

Expected: [[], [3], [6], [3, 6], [9], [3, 9], [6, 9], [3, 6, 9]]