Learn
Practice
Interview
Resources
Newsletter
F
Toggle theme
0
F
0
Toggle menu
Animations
← Back to All Animations
House Robber II
Bookmark
Recursion
Memoization
Tabulation
Space-Optimized
Input
Example 1
Example 2
Simple
Five houses
Single house
Custom
nums
=
[2, 7, 9, 3, 1]
2
h0
7
h1
9
h2
3
h3
1
h4
2
h0
7
h1
9
h2
3
h3
1
h4
2
h0
7
h1
9
h2
3
h3
1
h4
3
1
-1
0
2
0
1
-1
0
rob_linear(0, 1): rob house 1 for 7, or skip it
2
h0
7
h1
9
h2
3
h3
1
h4
3
1
7
-1
0
0
2
2
0
1
-1
0
rob_linear(0, 1) = max(7, 2) = 7
2
h0
7
h1
9
h2
3
h3
1
h4
3
1
7
-1
0
0
2
2
0
2
1
-1
0
rob_linear(0, 1)
2
h0
7
h1
9
h2
3
h3
1
h4
3
1
7
-1
0
0
2
2
0
2
1
-1
0
0
2
rob_linear(0, 0)
2
h0
7
h1
9
h2
3
h3
1
h4
4
2
0
1
3
1
2
0
1
rob_linear(1, 2)
2
h0
7
h1
9
h2
3
h3
1
h4
4
2
0
0
1
7
3
1
2
0
1
rob_linear(1, 1)
2
h0
7
h1
9
h2
3
h3
1
h4
4
2
9
0
0
1
7
3
1
7
2
0
1
rob_linear(1, 1)
2
h0
7
h1
9
h2
3
h3
1
h4
4
2
9
0
0
1
7
3
1
7
2
0
0
1
rob_linear(1, 1)
2
h0
7
h1
9
h2
3
h3
1
h4
max(11, 10) = 11
algo
master
.
io
Step:
5 houses in a circle, so houses 0 and 4 are neighbours.
0 / 46
Input
Example 1
Example 2
Simple
Five houses
Single house
Custom
nums
=
[2, 7, 9, 3, 1]
0 / 46
algo
master
.
io
Step:
5 houses in a circle, so houses 0 and 4 are neighbours.