Bird
Raised Fist0

Consider the same code as above. What is the output when candidates = [1] and target = 0?

medium🧾 Code Trace Q4 of Q15
Subsets & Combinations - Combination Sum (Reuse Allowed)
Consider the same code as above. What is the output when candidates = [1] and target = 0?
A[[]]
B[]
CError due to zero target
D[[1]]
Step-by-Step Solution
Solution:
  1. Step 1: Check base case when target=0

    Backtracking adds path when total == target; initially total=0, so path=[] is added.
  2. Step 2: Verify if recursion continues

    Since target=0, no further recursion; result contains [[]].
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Empty combination sums to zero -> [[]] [OK]
Quick Trick: Target zero means empty combination included [OK]
Common Mistakes:
MISTAKES
  • Returning empty list instead of [[]]
  • Assuming error on zero target
Trap Explanation:
PITFALL
  • Candidates often miss that empty path is a valid combination summing to zero.
Interviewer Note:
CONTEXT
  • Tests handling of edge cases with zero target.
Master "Combination Sum (Reuse Allowed)" 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