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?
- A. 15
- B. 18
- C. 30
- 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
- What is the length of the longest palindromic subsequence (not substring) of "ADCBEACD"?
- Houses hold [15, 35, 2, 19, 25, 31, 12, 36] 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, 8, 1, 1, 5, 5] sum to exactly 8?
- What is the length of the longest palindromic subsequence (not substring) of "BDDCCBDB"?
- Houses hold [40, 38, 22, 30, 6, 2, 31, 18] 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, 7, 3, 2, 8, 9, 1, 7, 1] sum to exactly 9?