Backtracking
Systematic exploration of all possibilities — subsets, permutations, and constraint satisfaction
0/48 solved
Subsets
Generate all subsets (power set) of a given set
Approach
At each recursive step, choose to include or exclude the current element. Build subsets incrementally by adding the current subset to results at every recursive call (not just at leaves).
How to Recognize
Problem asks for all subsets or combinations of elements
Need to generate the power set
Phrases like 'all possible subsets', 'subset sum'
Input has no duplicates (subsets I) or has duplicates (subsets II)
Pro Tips
For each element, two choices: include or exclude
For duplicates, sort first and skip consecutive equal elements at the same level
Total subsets = 2^n — be aware of exponential output
8
Total
0
Easy
8
Medium
0
Hard
Time
O(n * 2^n)
Space
O(n) recursion depth