Dodomeki
Sign in

39. House Robber

Easy

A street has houses in a row, each with an amount valores[i]. Because neighboring houses have connected alarms, you cannot choose two adjacent houses. Return the maximum total that can be taken.

Example 1
Input: valores = [2, 7, 9, 3, 1]
Output: 12
Explanation: Choose the houses with 2, 9, and 1.
Example 2
Input: valores = [4, 10, 3, 8]
Output: 18
Constraints
  • 0 <= valores.length <= 10^4
  • 0 <= valores[i] <= 10^5
Dynamic programmingArrays
Caso 1
valores =
[2,7,9,3,1]
Expected =
12
Caso 2
valores =
[4,10,3,8]
Expected =
18

Run checks these 2 cases. Submit runs all 6, including hidden ones.