Basic example
Input
rob([1, 2, 3, 1])
Output
4
Rob houses 1 and 3 (1-based): 1 + 3 = 4.
Full lesson preview
Maximize the amount a robber can steal from non-adjacent houses using dynamic programming.
Problem statement
Task
Examples
Input
rob([1, 2, 3, 1])
Output
4
Rob houses 1 and 3 (1-based): 1 + 3 = 4.
Input format
Output format
Constraints
Samples
Input
[2, 7, 9, 3, 1]
Output
12
Rob houses with amounts 2, 9, and 1 (or 7 and 3): max is 12.