Prompt: Given a list of numbers [i0 , i1 , i2 , … , in], each number represents the amount of money there is in a house. There are n houses with the index being the position of each house. Since there are security cameras in all houses and they take time to activate a automatic call to the police, you can not rob houses that are adjacent to the ones that you have already robbed. You want to find the maximum amount of money that you can rob for all houses.

Goal: Find the maximum amount of money that can be robbed with the restriction.

Note: You can not rob houses that are adjacent to the houses you have already robbed.

Examples:

1, 2, 3, 1 Total amount you can rob = 1 + 3 = 4.

2, 7, 9, 3, 1 Total amount you can rob = 2 + 9 + 1 = 12.

Solution:
Let’s say you have a list, x1, x2, x3, x4, x5.
If x1 > x2, then you want to rob x1.
If x2 > x1, then you want to rob x2.
However, if x3 > x2 then you want to rob x3 and x1. If x3 < x2, then you just want to rob x2.
This is a common situation in all 3-adjacent houses where the third house determines if you should rob the third house and the first house or just rob the second house. Knowing this, we can use dp to pick which houses to rob depending on the previous two houses.

The new problem is that how do we compare the previous two houses if we’re in the first house? We start evaluating the second house first and compare it to the first house and a phantom house that is worth 0 money to start with.