Algorithms Playbook
← All problems
Medium1D dynamic programming →Similar to: House Robber

Rob the street without alarms

Problem

Houses on a street each hold some money nums[i]. Two adjacent houses have linked alarms, so you cannot take from both. Return the maximum you can collect.

Examples

Input: [2, 7, 9, 3, 1]

Output: 12

2 + 9 + 1.

Input: [5, 1, 1, 5]

Output: 10

Hints

    Try it first. Every hint reveals a bit more.

    Solution