mediumDynamic Programming

House Robber

## Problem

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed.

The only constraint is that **adjacent houses have connected security systems** — robbing two adjacent houses on the same night will alert the police.

Given an integer array `nums` representing the amount of money at each house, return the **maximum amount of money you can rob** without alerting the police.

Examples

Input
nums = [1,2,3,1]
Output
4
Rob house 1 (1) then house 3 (3) = 4
Input
nums = [2,7,9,3,1]
Output
12
Rob house 1 (2) + house 3 (9) + house 5 (1) = 12

Constraints

1 <= nums.length <= 100 0 <= nums[i] <= 400
Python
Loading...