Bird
Raised Fist0

Consider the following Python code implementing the optimal backtracking solution for Combination Sum II. What is the final returned list when calling combinationSum2([1,2,2], 4)?

easy🧾 Code Trace Q12 of Q15
Subsets & Combinations - Combination Sum II (No Reuse, Duplicates)
Consider the following Python code implementing the optimal backtracking solution for Combination Sum II. What is the final returned list when calling combinationSum2([1,2,2], 4)?
A[[1,2,2]]
B[[1,2],[2]]
C[[1,2],[2,2]]
D[[1,2],[2,2],[1,2,2]]
Step-by-Step Solution
  1. Step 1: Sort candidates and start backtracking

    Sorted candidates: [1,2,2]. Start from index 0 with target=4.
  2. Step 2: Explore combinations skipping duplicates at same level

    Try 1 -> target=3, then try 2 at next index -> target=1, next 2 is duplicate at same level skipped. No further candidates fit. Backtrack and try 2 at index 1 -> target=2, next 2 at index 2 -> target=0, add [2,2]. Both [1,2,2] and [2,2] are valid unique combinations.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Both [1,2,2] and [2,2] sum to 4 without reuse and duplicates skipped [OK]
Quick Trick: Duplicate skipping prevents repeated combinations [OK]
Common Mistakes:
MISTAKES
  • Including partial sums like [2]
  • Allowing reuse of elements
  • Not skipping duplicates at same recursion level
Trap Explanation:
PITFALL
  • Candidates may think [2,2] alone is invalid, but sum is 4 and no reuse is needed here.
Interviewer Note:
CONTEXT
  • Tests candidate's ability to mentally execute backtracking with duplicate skipping.
Master "Combination Sum II (No Reuse, Duplicates)" 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