mediumBacktrackingPure DSA~22 min
Feature Toggle Subsets
A release tool wants to enumerate every possible combination of independent feature toggles so QA can test each configuration. Given the distinct toggle ids, produce all subsets — the full power set.
Problem
Given an array of distinct integers, return all possible subsets (the power set). The solution set must not contain duplicate subsets; any order is accepted.
Input
An array nums of length n (0 ≤ n ≤ 16) of distinct integers.
Output
A list of all 2^n subsets, each a list of integers.
Constraints
- 0 ≤ n ≤ 16
- All elements are distinct
- Output contains exactly 2^n subsets
Examples
Example 1
Input
nums = [1, 2, 3]
Output
[[], [1], [2], [1,2], [3], [1,3], [2,3], [1,2,3]]
All 2^3 = 8 subsets, including the empty set.
Example 2
Input
nums = [0]
Output
[[], [0]]
Two subsets: empty and the singleton.