Data Structures & AlgorithmsHard

How many subsets of {1, 2, ..., 9} have sum exactly 10 (the empty set is not counted, and each value is used at most once)?

  1. A. 4
  2. B. 41
  3. C. 9
  4. D. 10

Correct answer: C. 9

Subset-sum counting with each value used at most once is a 0/1 DP over sums. Including the empty subset (which sums to 0, not 10, so it is not the issue here), restricting the size, or counting sums up to 10 each answer a different question.

More Arrays, Strings, Linked Lists, Stacks, Queues and Hashing questions

Exams that ask this topic