Given an array nums
where nums[i]
represents the money in the i-th house:
Return the maximum amount of money you can rob without alerting the police.
Constraints:
Examples:
// Example 1: console.log(rob([3,4,3])); // Output: 4 // Explanation: Can't rob houses 0 and 2 (adjacent in circle) // Maximum is house 1 (4) // Example 2: console.log(rob([2,9,8,3,6])); // Output: 15 // Explanation: Can't rob houses 0,2,4 (0 and 4 adjacent in circle) // Maximum is houses 1,4 (9 + 6 = 15)