/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. The output must not contain duplicate subsets. The order of subsets in the output can be arbitrary.

Example 1

Input: [4, 5]

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

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

Example 2

Input: [-1, 2, 3]

Output: [[], [-1], [2], [-1, 2], [3], [-1, 3], [2, 3], [-1, 2, 3]]

Explanation: All possible subsets of [-1, 2, 3] 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: [2, 0]

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

Case 3

Input: [-2, 1, 4]

Expected: [[], [-2], [1], [-2, 1], [4], [-2, 4], [1, 4], [-2, 1, 4]]