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: [1,2,3,1] Output: 4
Input: [2,7,9,3,1] Output: 12
Input: [5] Output: 5
Your program must print a single integer representing the maximum money that can be robbed.
No submissions yet.
Discuss dynamic programming approaches, state transitions, and space optimization.