Data Structures & AlgorithmsHardProduct Company SDE · CP practice
How many subsets (by index, so equal values at different positions count separately) of [1, 7, 3, 2, 8, 9, 1, 7, 1] sum to exactly 9?
- A. 24
- B. 11
- C. 13
- D. 12
Correct answer: D. 12
Counting knapsack: dp[c] += dp[c−x] for each element with c descending → 12.
More Coding Interview Problems questions
- What is the length of the longest palindromic subsequence (not substring) of "CDDDBCADE"?
- Houses hold [15, 30, 28, 6, 27, 12, 20, 20] units of cash. You cannot rob two adjacent houses. What is the maximum amount you can rob?
- How many subsets (by index, so equal values at different positions count separately) of [4, 2, 9, 6, 2, 7, 6] sum to exactly 15?
- What is the length of the longest palindromic subsequence (not substring) of "DDCBAEBDC"?
- Houses hold [38, 12, 22, 29, 7, 8, 37] units of cash. You cannot rob two adjacent houses. What is the maximum amount you can rob?
- How many subsets (by index, so equal values at different positions count separately) of [1, 9, 7, 5, 2, 5] sum to exactly 16?