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

Approaches

Related problems

Start free on Cariara · Coding problems · System design studio

Starting Python
No results yet.

          
↑↓ move ↵ open esc close

Labs

Loading labs…

Run with your own input

Starting Python

Loading Python…