Back to Practice
#0097
House Robber
MediumDSA25 min20 XP
Problem
Given non-negative house values, return the maximum sum you can rob without taking adjacent houses.
Why This Matters
This is the classic include/exclude DP pattern that appears in many scheduling and selection problems.
Function Signature
def rob(nums):
Examples
Example 1
Input[2, 7, 9, 3, 1]
Output12
Rob houses with values 2, 9, and 1.
Constraints
- Return the exact structure requested.
- Handle the edge cases mentioned in the prompt.
- Prefer clear logic over clever one-liners.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Input[2, 7, 9, 3, 1]
Expected12
Rob houses with values 2, 9, and 1.
Hidden Test Categories
empty listone houseall equal values