You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security systems connected and 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 = [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 2:

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


&nbsp;
Constraints:


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


class Solution:
    def rob(self, nums: List[int]) -> int:
        # [rob1,rob2,n,n+1]
        # 1 | 2 | 3 | 1  
   #index 0   1   2   3
        # so upto last index it depends on previous 2 values :
    # here upto 2nd index max rob is 1+3=4; not choosing adjacent element 2
    # and upto 1st index  max rob is 2 ; not choosing any adjacent elements
    # so at 3rd index it depend on prev rob value and 1st index rob value+last value
    # i.e max(2+(val at last index),4)
        rob1=0;rob2=0;
        for i in nums:
            temp=max(rob1+i,rob2);
            rob1=rob2;
            rob2=temp;
        return rob2;
class Solution {
    public int rob(int[] nums) {
        int[] t = new int[nums.length] ;
        for(int i=0; i<t.length; i++){
            t[i] =-1;
        }
       return helper(nums,0,t);
    }
    static int helper(int[] nums, int i,int[] t){
        if(i>=nums.length){
            return 0;
        }
        if(i==nums.length-1){
            return nums[i];
        }
        if(t[i] != -1){
            return t[i];
        }

        int pick = nums[i] + helper(nums,i+2,t);
        int unpicked = helper(nums,i+1,t);
        t[i] = Math.max(pick,unpicked);
        return t[i];

    }
}
class Solution {
public:
    int helper(int i, vector<int>& nums) {
        if(i == 0) return nums[i];
        if(i < 0) return 0;

        int pick = nums[i] + helper(i-2, nums);
        int not_pick = 0 + helper(i-1, nums);

        return max(pick,not_pick);
    }
    int rob(vector<int>& nums) {
        return helper(nums.size()-1, nums);
    }
};
const max=(x,y)=>x>y?x:y
var rob = function(nums) {
     if(nums.length==1) return(nums[0]);
    let temp=[]
    temp[0]=nums[0];
        temp[1]=max(nums[0],nums[1]);

        for(let i =2;i<nums.length;i++){
            temp[i] = max(temp[i-1],nums[i]+temp[i-2]);
        }
        // console.log(temp)
        return(temp[nums.length-1]);
};
House Robber