CodeMentor.
Ask AIProblemsLearnC++TCSCore CSHRProgress
0Lv 1
ProblemsIntro Dynamic Programming

House Robber

Medium
LeetCode
2/3
MediumIntro Dynamic ProgrammingLeetCode #198

House Robber

dp[i] = max(dp[i-1], dp[i-2]+nums[i]). Can't rob adjacent.

Examples

Example 1

Input

4
1 2 3 1

Output

4
Example 2

Input

5
2 7 9 3 1

Output

12

Stuck? Take a nudge

C++17Autosaves