CodeMentor
.
Ask AI
Problems
Learn
C++
TCS
Core CS
HR
Progress
Search
Ctrl
K
0
Lv 1
Problems
Intro Dynamic Programming
House Robber
Medium
LeetCode
2/3
00:00
Hint
Run
Ctrl
↵
Submit
Description
Lesson
Code walk
Solution
Medium
Intro Dynamic Programming
LeetCode #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
Reveal hint 1 of 3
C++17
Autosaves
Reset
Console
Run your code to see results