Data Structures & AlgorithmsHardProduct Company SDE · CP practice

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

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

Correct answer: B. 3

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

More Coding Interview Problems questions

Exams that ask this topic