Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
House Robber
Bookmark
Recursion
Memoization
Tabulation
Space-Optimized
Input
Example 1
Example 2
Example 3
Adjacent pattern
Single house
Two houses
Custom
nums
=
[2, 7, 9, 3, 1]
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
2
1
0
-1
0
1
0
-1
2
1
0
-1
0
15 calls in total
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
2
1
0
-1
0
1
0
-1
2
1
0
-1
0
15 calls in total
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
2
1
0
-1
0
1
0
-1
2
1
0
-1
0
rob_from(3): skip house 3, or rob it for 3
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
2
1
0
-1
0
1
0
-1
2
1
0
-1
0
rob_from(1): skip house 1, or rob it for 7
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
2
1
7
0
2
-1
0
0
1
0
-1
2
1
0
-1
0
rob_from(1) = max(2, 7) = 7
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
2
11
1
7
0
2
-1
0
0
2
1
0
-1
2
1
0
-1
0
rob_from(1)
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
2
11
1
7
0
2
-1
0
0
2
1
0
2
-1
2
1
0
-1
0
rob_from(-1)
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
11
2
11
1
7
0
2
-1
0
0
2
1
7
0
2
-1
0
2
1
0
-1
0
rob_from(2)
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
11
2
11
1
7
0
2
-1
0
0
2
1
7
0
2
-1
0
2
1
0
2
-1
0
rob_from(0)
2
h0
7
h1
9
h2
3
h3
1
h4
4
3
11
2
11
1
7
0
2
-1
0
0
2
1
7
0
2
-1
0
2
1
7
0
2
-1
0
0
rob_from(0)
2
h0
7
h1
9
h2
3
h3
1
h4
4
12
3
11
2
11
1
7
0
2
-1
0
0
2
1
7
0
2
-1
0
2
11
1
7
0
2
-1
0
0
2
Best loot is 12
algo
master
.
io
Step:
5 houses. rob_from(i) asks for the best loot from houses 0 through i.
0 / 38
Input
Example 1
Example 2
Example 3
Adjacent pattern
Single house
Two houses
Custom
nums
=
[2, 7, 9, 3, 1]
0 / 38
algo
master
.
io
Step:
5 houses. rob_from(i) asks for the best loot from houses 0 through i.