Choose non-adjacent houses to maximize the total amount of money robbed.
You are given a row of houses, where each house contains some amount of money. A robber wants to maximize the total amount stolen, but cannot rob two adjacent houses on the same night.
Return the maximum amount of money the robber can steal without triggering the alarm.
nums, where nums[i] is the amount of money in the i-th house.i is adjacent to i-1 and i+1.1 <= nums.length0 <= nums[i]Example 1
Input
nums = [1,2,3,1]
Output
4
Explanation
Rob houses 1 and 3 (1-indexed), for a total of 1 + 3 = 4.
Example 2
Input
nums = [2,7,9,3,1]
Output
12
Explanation
A best choice is houses with values 2, 9, and 1, giving 12.
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.