Data Structures & AlgorithmsHardProduct Company SDE · CP practice

Houses hold [16, 29, 33, 40, 3, 32, 33, 13] units of cash. You cannot rob two adjacent houses. What is the maximum amount you can rob?

  1. A. 85
  2. B. 114
  3. C. 119
  4. D. 113

Correct answer: B. 114

dp[i] = max(dp[i−1], dp[i−2]+a[i]) → 114. Taking every other house (85) is not always optimal.

More Coding Interview Problems questions

Exams that ask this topic