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?

  1. A. 100
  2. B. 107
  3. C. 104
  4. 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

Exams that ask this topic