You are a robber planning to rob houses along a street. Each house has a certain amount of treasure stashed, the only constraint stopping you from robbing every one of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given a list of integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight without alerting the police.
nums = [1, 2, 3, 1]
4
Rob house 0 and house 2 for 1 + 3 = 4. Houses 2 and 3 are adjacent, so the two largest values cannot both be taken.
nums = [2, 7, 9, 3, 1]
12
Rob houses 0, 2, and 4 for 2 + 9 + 1 = 12. Taking the two largest values that are not adjacent, 7 and 3, yields only 10, so picking greedily by value is not enough.
1 <= nums.length <= 1000 <= nums[i] <= 400