Bird
Raised Fist0

What is the output of the subsets function when called with nums = [5]?

medium🧾 Code Trace Q4 of Q15
Subsets & Combinations - Subsets
What is the output of the subsets function when called with nums = [5]?
A[[], []]
B[[5]]
C[[5], []]
D[[], [5]]
Step-by-Step Solution
Solution:
  1. Step 1: Trace mask values for n=1

    mask=0 -> [], mask=1 -> [5]
  2. Step 2: Check subsets appended

    Result should be [[], [5]] as subsets include empty and full element.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Code appends empty subset and subset with 5 [OK]
Quick Trick: Single element subsets include empty and full element [OK]
Common Mistakes:
MISTAKES
  • Confusing order of subsets
  • Misreading loop boundaries
Trap Explanation:
PITFALL
  • Candidates may confuse order or duplicate empty subsets due to loop logic.
Interviewer Note:
CONTEXT
  • Tests edge case handling with single-element input
Master "Subsets" in Subsets & Combinations

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Subsets & Combinations Quizzes