Solvarch
DSA ProblemsProgressPlanRoadmapsReviewCheat SheetsCompaniesSystem DesignCS FundamentalsQuestion Bank
Theme
Problems

Subsets

Medium
backtrackingbit-manipulationrecursion

Given an array of distinct integers, return all possible subsets (the power set).

Input: one line of space-separated integers. Output: one subset per line, elements in ascending order (the empty subset prints as an empty line). Subsets may be produced in any order — the template prints them canonically.

Example 1
Input:
1 2 3
Output:

1
1 2
1 2 3
1 3
2
2 3
3
Example 2
Input:
0
Output:

0

Constraints

  • 1 ≤ nums.length ≤ 10
  • Distinct values.
Watch a video walkthrough

Run your code against the sample tests, or Submit to run the full suite.