Data Structures & AlgorithmsHardProduct Company SDE · CP practice

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

  1. A. 0
  2. B. 3
  3. C. 1
  4. D. -1

Correct answer: C. 1

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

More Coding Interview Problems questions

Exams that ask this topic