Here, the maximum robbed money at every house would equal to the maximum of: the amount stolen at the previous house, the amount stolen at the house before + the current house's money.
We can hence turn this problem into a dynamic programming problem, where the result is the amount stolen at the last house.
As the first and the last houses are connected, the maximum sum equals the maximum of the maximum sum of the houses without the first or without the last. We apply the algorithm from the first problem in two passes and compare the results.
198. House Robber
Here, the maximum robbed money at every house would equal to the maximum of: the amount stolen at the previous house, the amount stolen at the house before + the current house's money. We can hence turn this problem into a dynamic programming problem, where the result is the amount stolen at the last house.
213. House Robber II
As the first and the last houses are connected, the maximum sum equals the maximum of the maximum sum of the houses without the first or without the last. We apply the algorithm from the first problem in two passes and compare the results.