PIXELBANKv9.1.0
Menu

Given an integer array nums of unique elements, return all possible subsets (the power set).

Output each subset on a separate line as space-separated integers (empty subset as empty line). Subsets sorted by size, then lexicographically.

Example:

Input:
1,2,3
Output:

1
2
3
1 2
1 3
2 3
1 2 3
Reasoning:
  • The problem starts by generating subsets of size 1 from the input array nums = [1,2,3], resulting in subsets [1], [2], and [3].
  • Next, it generates subsets of size 2 by combining each pair of unique elements: [1,2], [1,3], and [2,3].
  • Then, it generates the subset of size 3, which includes all elements: [1,2,3].
  • The subsets are then sorted first by size (from smallest to largest) and then lexicographically, resulting in the output:

1 2 3 1 2 1 3 2 3 1 2 3

Constraints:

  • 1 <= len(nums) <= 10
  • -10 <= nums[i] <= 10
  • All elements are unique
🔒

Editor locked

The code editor is locked for Pro problems. It is only available for free problems. Please upgrade to gain access to the code editor for all problems.

solution.py

Test Results

0/0
Run code to see test results.
Subsets - Medium | PixelBank