House Robber
Medium · Dynamic Programming · Array · Dynamic Programming
Problem
Each house on a street holds nums[i] in cash. You cannot take from two adjacent houses. Return the most you can take.
Examples
Input: nums = [1,2,3,1] Output: 4
Take house 0 and house 2: 1 + 3.
Input: nums = [2,7,9,3,1] Output: 12
Houses 0, 2 and 4: 2 + 9 + 1.
Constraints
- 1 <= len(nums) <= 100
- 0 <= nums[i] <= 400
Approaches
- Explicit table — time O(n), space O(n)
Related problems
Start free on Cariara · Coding problems · System design studio