Data Structures & AlgorithmsHardProduct Company SDE · CP practice
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?
- A. 100
- B. 107
- C. 104
- D. 156
Correct answer: C. 104
dp[i] = max(dp[i−1], dp[i−2]+a[i]) → 104. Taking every other house (104) is not always optimal.
More Coding Interview Problems questions
- How many subsets (by index, so equal values at different positions count separately) of [1, 9, 7, 5, 2, 5] sum to exactly 16?
- A function returns the length of the longest strictly increasing subsequence (not necessarily contiguous). What does it return for [18…
- How many subsets (by index, so equal values at different positions count separately) of [9, 8, 8, 2, 2, 1, 5, 1, 6] sum to exactly 12?
- What is the length of the longest palindromic subsequence (not substring) of "BBCABABC"?
- A function returns the length of the longest strictly increasing subsequence (not necessarily contiguous). What does it return for [15, 1…
- How many subsets (by index, so equal values at different positions count separately) of [1, 3, 3, 5, 1, 5, 9, 5, 1] sum to exactly 11?