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&nbsp;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.

&nbsp;
Example 1:

Input: nums = [2,3,2]
Output: 3
Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.


Example 2:

Input: nums = [1,2,3,1]
Output: 4
Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
Total amount you can rob = 1 + 3 = 4.


Example 3:

Input: nums = [1,2,3]
Output: 3


&nbsp;
Constraints:


	1 &lt;= nums.length &lt;= 100
	0 &lt;= nums[i] &lt;= 1000


class Solution(object):
    def rob(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        if len(nums) == 1:
            return nums[0]
        def helper(nums):
            one, two = 0, 0
            for i in nums:
                temp = max(i + one, two)
                one = two
                two = temp
            return two
        
        return max(helper(nums[:-1]), helper(nums[1:]))
class Solution {
    public int rob(int[] nums) {
        if(nums.length==1){
            return nums[0];
        }
        int[] t = new int[nums.length];
        for(int i = 0 ; i < t.length;i++){
            t[i] = -1;
        }
        int[] k = new int[nums.length];
        for(int i = 0 ; i < k.length;i++){
            k[i] = -1;
        }
        return Math.max(helper(nums,0,0,t),helper(nums,1,1,k));
    }
    static int helper(int[] nums, int i,int start , int[] t){
        if(start==0 && i==nums.length-2){
            return nums[i];
        }
        if(start==1 && i==nums.length-1){
            return nums[i];
        }
        if(start==0 && i>=nums.length-1){
            return 0;
        }
        if(start==1 && i>=nums.length){
            return 0;
        }
        if(t[i] != -1){
            return t[i];
        }
        int pick = nums[i]+helper(nums,i+2,start,t);
        int notpick = helper(nums,i+1,start,t);
        t[i] = Math.max(pick,notpick);
        return t[i];
    }
}
class Solution {
public:
    int rob(vector<int>& nums) 
    {
        int n = nums.size();  
        if(n == 1)
        {
            return nums[0];
        }
        //dp[n][2][1]
        vector<vector<vector<int>>> dp(n+1, vector<vector<int>>(2, vector<int>(2, -1)));
        
        int maxm = 0;
        for(int i = 0; i < n; i++)
        {
            for(int j = 0; j < 2; j++)
            {
                for(int k = 0; k < 2; k++)
                {
                    maxm = max(maxm, dp_fun(dp, i, j, k, nums));
                }
            }
        }
        
        return maxm;
        
    }
    
    int dp_fun(vector<vector<vector<int>>> &dp, int ind, int num, int last, vector<int> &ar)
    {
        int n = ar.size();
        if(dp[ind][num][last] == -1)
        {
            if(ind == 0)
            {
                if(last == 1)
                {
                    dp[ind][num][last] = 0;
                }
                else 
                {
                    if(num == 1)
                    {
                        dp[ind][num][last] = ar[ind];
                    }
                    else 
                    {
                        dp[ind][num][last] = 0;
                    }
                }
            }
            else if (ind == n-1)
            {
                if(num == 0)
                {
                    dp[ind][num][last] = 0;
                }
                else 
                {
                    if(last == 0)
                    {
                        dp[ind][num][last] = dp_fun(dp, ind-1, 1, 0, ar);    
                    }
                    else 
                    {
                        dp[ind][num][last] = ar[ind] + dp_fun(dp, ind-1, 0, 1, ar);
                    }
                }
            }
            else 
            {
                if(num == 1)
                {
                    dp[ind][num][last] = max(ar[ind] + dp_fun(dp, ind-1, 0, last, ar), dp_fun(dp, ind-1, 1, last, ar));
                }
                else 
                {
                    dp[ind][num][last] = dp_fun(dp, ind-1, 1, last, ar);
                }
            }
        }
        return dp[ind][num][last];
    }
};
var rob = function(nums) {

    let dp = []
    dp[0] = [0,0]
    dp[1] = [nums[0],0]

    for(let i=2; i<=nums.length;i++){
        let val = nums[i-1]

        let rob = dp[i-2][0] + val
        let dont = dp[i-1][0]
        let noFirst = dp[i-2][1] + val

        let best = (rob>=dont)?rob:dont

        if(dp[i-1][1]>noFirst) noFirst=dp[i-1][1]

        if(i!=nums.length){
            dp[i] = [best,noFirst]
        }else{
            dp[i] = [dont,noFirst]
        }

    }
    return (dp[nums.length][0]>=dp[nums.length][1]) ? dp[nums.length][0]:dp[nums.length][1]

};
House Robber II