CodeOath
← All problems

House Robber

Medium
dynamic-programming

You are a robber planning to rob houses along a street, where nums[i] is the amount of money stashed in house i. Adjacent houses have connected security systems — robbing two adjacent houses trips the alarm. Return the maximum amount of money you can rob without robbing two adjacent houses.

Example:

Input: nums = [1,2,3,1]
Output: 4
Explanation: Rob house 1 (money = 1) and house 3 (money = 3). Total = 1 + 3 = 4.

Constraints:

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