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 of them is that adjacent houses have security systems connected and it will automatically contact the police if two adjacent houses were broken into on the same night. Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
Example 1
Input: nums = [2,7,9,3,1]
Output: 12
Explanation: Rob houses 0, 2 and 4 for 2 + 9 + 1 = 12. None of them are next to each other, and no other safe choice collects more.
Example 2
Input: nums = [1,2,3,1]
Output: 4
Explanation: Rob houses 0 and 2 for 1 + 3 = 4.
Example 3
Input: nums = [5]
Output: 5
Explanation: There is only one house, so rob it for 5.
At each house you either skip it (keep the best total up to the previous house) or rob it (its money plus the best total up to two houses back). dp[i] = max(dp[i-1], dp[i-2] + nums[i]).
Run checks all cases above. Submit evaluates all test cases.