How do you generate all subsets of a set of n distinct numbers?
PICTURE THIS: JAVASCRIPT EVENT LOOP
Simple meaning
Backtrack: at each index either include nums[i] or skip it, recording a copy when i reaches n.
WHY — Recursion instead of guessing?
Why interviewers care about Recursion:
question about Recursion.
trade-offs, and what you would actually do on a DSA project - not buzzwords.
Name the idea, why it exists, then one short example.
End with when you use it and one common pitfall.
STEPS — What happens step by step?
Before you speak the answer, walk the interviewer through these steps:
- 1Backtrack: at each index
either include nums[i] or skip it, recording a copy when i reaches n.
- 2There are 2^n subsets,
so time is O(n * 2^n) to copy lists and space is O(n) for the call stack besides the output.
- 3Bit masks from 0
to 2^n-1 are the iterative twin.
- 4Give an example
One tiny concrete case you can say aloud.
- 5Common mistake
What juniors usually get wrong.
- 6Close
When you pick this over the alternative.
EXAMPLE — See it in action
Here's a short line you can speak, broken into clear beats:
Note: Adapt this scaffold to your own project — keep it under 60–90 seconds.
Key takeaway
Backtrack: at each index either include nums[i] or skip it, recording a copy when i reaches n. There are 2^n subsets, so time is O(n * 2^n) to copy lists and space is O(n) for the call stack besides the output.