public class Solution {

public int rob(int[] nums) {

if(nums.length==0) return 0;

// add two fake houses to avoid index out of bound error

int[] maxVal = new int[nums.length+2];

for(int i= 0; i<nums.length; i++) {

maxVal[i+2] = Math.max(maxVal[i] + nums[i], maxVal[i+1]);

}

```
return maxVal[nums.length+1];
}
```

}