← Dynamic Programming

Pattern Recognition Drill

#64 — House robber

Medium Dynamic Programming

The Problem

Max amount you can rob without robbing two adjacent houses.

What approach would you use?

Think about it before scrolling down.

Key Signals

Dynamic Programming

dp[i] = max(dp[i-1], dp[i-2] + val[i]). Include or exclude each house. O(n) time, O(1) space.

Common Trap

Greedy (always rob the largest) fails — adjacent constraint makes local greedy suboptimal.

← #63 #65 →