to get the max profit i check if robbing a house is better than skipping while folllowing the adjacent house rule
-
Time complexity:O(N)
-
Space complexity:O(1)
function rob(nums: number[]): number {
let prev1 = 0
let prev2 = 0
for (let num of nums) {
let temp = prev1
prev1 = Math.max(prev1, prev2 + num)
prev2 = temp
}
return prev1
}