Back to Practice
#0114
Generate All Subsets
MediumDSA25 min20 XP
Problem
Given a list of distinct values, return all subsets. Output order does not matter.
Why This Matters
Subsets are the include/exclude foundation behind many combinatorics, search, and backtracking problems.
Function Signature
def subsets(items):
Examples
Example 1
Input[1, 2]
Output[[], [1], [2], [1,2]] in any order
Each item is either excluded or included.
Constraints
- Return the requested value exactly.
- Handle the stated edge cases.
- Keep the solution readable.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[1, 2]
Expected[[], [1], [2], [1,2]] in any order
Each item is either excluded or included.
Hidden Test Categories
empty inputthree valuesstring values