House Robber

Medium Solved

Description

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

The only constraint stopping you from robbing each house is that adjacent houses have security systems connected. If two adjacent houses are robbed, the alarm will be triggered.

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

Input format / Clarification:

  • Line 1: JSON array of integers

Example 1:

Input:
[1,2,3,1]

Output:
4

Example 2:

Input:
[2,7,9,3,1]

Output:
12

Example 3:

Input:
[5]

Output:
5

Note:

Your program must print a single integer representing the maximum money that can be robbed.

Your Submissions

No submissions yet.

Discuss

Discuss dynamic programming approaches, state transitions, and space optimization.

Test Cases