Question
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.
Given an integer array
numsrepresenting the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
Idea
- The same as Leetcode - House Robber except we need to circularly index to see if we can get more value
- Actually I think the only extra stipulation here is that the first and last houses are now neighbours
- So now we can only rob the last house if we did not rob the first house and we need a mechanism to know that information
- Instead of a mechanism to know this information, we know that if we rob the first house we can’t rob the last house, and if we rob the last house, we can’t rob the first house, so we can just take the max of those two choices