← Back to DSA Animator
House Robber II LC #213 Medium Circular DP
Problem

Same as House Robber but houses are arranged in a circle. First and last are adjacent. Return max money without alerting.

Approach
Run House Robber twice: (1) skip last house, (2) skip first house. Take max.
Try Examples
Approach
Two Passes — Break the Circle
Pass 1: houses [0..n-2] (skip last). Pass 2: houses [1..n-1] (skip first). Return max of both.
Two Passes
Load an example.
Variables
Pass 1
Pass 2
Result
Step Logic
Press ▶ Play or Next Step to begin.
💰
Ready
0 / 0
Select an example.
Algorithm
1
robRange(nums, 0, n-2) — skip last
2
robRange(nums, 1, n-1) — skip first
3
return max(pass1, pass2)
Time
O(n)
Space
O(1)
Why This Works

In a circle, we can't rob both first and last. So the optimal is either: best excluding last, or best excluding first. These two linear subproblems cover all valid solutions.