Data Structures & AlgorithmsHardProduct Company SDE · CP practice

How many subsets (by index, so equal values at different positions count separately) of [8, 7, 8, 6, 9, 3, 6, 1, 2] sum to exactly 16?

  1. A. 15
  2. B. 18
  3. C. 30
  4. D. 12

Correct answer: A. 15

Counting knapsack: dp[c] += dp[c−x] for each element with c descending → 15.

More Coding Interview Problems questions

Exams that ask this topic