# Approach 1: Keep track of amount robbed using DP

The approach is very similar to House Robber (which I strongly recommend reading first)

Since the array is circular this time, we will keep track of two lists of sums, one with `nums` (`dpl`) and one without `nums` (`dpr`). This way when we reach the last element, we will only check the array that does not have `nums` to make sure that first and the last houses are not robbed together.

`class Solution(object):    def rob(self, nums):        """        https://leetcode.com/problems/house-robber-ii/description/        :type nums: List[int]        :rtype: int        """        lea = len(nums)        if lea == 0:            return 0        if lea == 1:            return nums        if lea == 2:            return max(nums)        if lea == 3:            return max(nums, nums, nums)        if lea == 4:            return max(nums + nums, nums + nums)        dpl =  * lea        dpl, dpl, dpl, dpl = nums, nums, nums + nums, nums + nums        dpr =  * lea        dpr, dpr, dpr, dpr = nums, nums, nums, nums + nums        for i in range(4, lea-1):            dpl[i] = nums[i] + max(dpl[i-2], dpl[i-3])            dpr[i] = nums[i] + max(dpr[i-2], dpr[i-3])        dpr[-1] = nums[-1] + max(dpr[-4], dpr[-3])        return max(dpl[-2], dpl[-3], dpr[-1], dpr[-2])`

Another added difference between this and House Robber I is that our base case has expanded from 3 to 4, because this time we are storing `dpl` as `nums + nums` and `dpr` as `nums + nums` to make sure `dpl` contains the first element while `dpr` does not.

Time Complexity: O(N)

Space Complexity: O(N)