House Robber

Dynamic Programming, problem 3 of 9

House Robber

Medium

LC #198

take or skip1d dp

Not attempted yet

nums[i] is the money in house i along a street. Robbing two adjacent houses sets off an alarm. Return the most money you can take without triggering it.

Example 1

Input: nums = [1, 2, 3, 1]
Output: 4
houses 0 and 2: 1 + 3

Example 2

Input: nums = [2, 7, 9, 3, 1]
Output: 12
houses 0, 2, 4: 2 + 9 + 1

Example 3

Input: nums = [2, 1, 1, 2]
Output: 4
houses 0 and 3

Constraints

  • 1 ≤ len(nums) ≤ 1000
  • 0 ≤ nums[i] ≤ 1000

Python

Loading draft…

Test results

8 tests available

No results yet

Run tests your code against the examples; Submit runs the hidden tests too.

3 examples, 5 hidden

Run examples, then submit all tests.