JavaScript, React, Python, Angular, HTML.
i++) { const temp = currMax; currMax = Math.max(currMax, prevMax + nums[i]); prevMax = temp; } return currMax; } const nums = [1, 2, 3, 1]; console.log(rob(nums)); // Output: 4 Another Implementation, /** * Brute Force - DFS * Time O(2^N) | Space O(N) * https://leetcode.com/problems/house-robber/ *