Given a set of distinct integers, explain how you would generate all possible subsets (the power set).
For example, given [1, 2, 3], the output should be: [], [1], [2], [3], [1,2], [1,3], [2,3], [1,2,3].
Describe your approach step by step, explain why it correctly produces all subsets, and analyze the time and space complexity.
How to approach it
- Hint 1
For each element, you have two choices: include it in the current subset or exclude it. How can you structure this as a decision tree?
- Hint 2
Think recursively -- at each index, branch into two paths (take or skip), then move to the next index.
- Hint 3
How many total subsets does a set of n elements have? That tells you the time complexity.
Ready to answer it out loud?
Record your answer in 1:30 and Preptile scores it 1–10 with specifics — what landed, what you skipped, and what to say next time.
Practising needs an invite code. Join the waitlist and we’ll send you one.