Back to Practice
#0270
House Robber II
MediumDSA28 min20 XP
Problem
Given non-negative house values in a circle, return the maximum money you can rob without robbing adjacent houses.
Why This Matters
This problem shows how a circular constraint can often be split into two linear DP problems.
Function Signature
def rob_circular(nums):
Examples
Example 1
Inputnums = [2, 3, 2]
Output3
The first and last houses are adjacent, so rob only the middle house.
Constraints
- Return the exact requested value.
- Handle edge cases cleanly.
- Use the intended DSA pattern when brute force would scale poorly.
CodePython
Visible browser tests run here when available.
Testcases2 visible / 3 hidden categories
Circle conflict
Input[2,3,2]
Expected3
Robbing both 2s is illegal because they are adjacent in the circle.
Choose middle and end
Input[1,2,3,1]
Expected4
Rob houses with values 1 and 3 in the best linear split.
Hidden Test Categories
single housetwo housesall equal values