ntree.aiHouse Robber
House Robber
mediumsolvedattempted
You are given an array of integers nums, where nums[i] is the amount of money in the ith house on a street. You cannot take money from two houses that stand next to each other.
Return the largest amount you can take.
Example 1:
Input: nums = [4, 2, 7, 3]
Output: 11
Explanation: Take house 0 and house 2, so 4 + 7 = 11.
Example 2:
Input: nums = [2, 7, 9, 3, 1]
Output: 12
Explanation: Take house 0, house 2 and house 4, so 2 + 9 + 1 = 12.
Constraints:
1 <= length of nums <= 1000 <= nums[i] <= 400
def rob(nums: list[int]) -> int: pass Press Visualise to step through your code.