DSA · Dynamic Programming · #83
House Robber II
Module 47 · difficulty 3/5·⏱ 30:00starts on first keystroke
You are a robber planning to loot houses arranged in a **circle**, meaning the first house is the neighbour of the last. Each house has `nums[i]` money stashed. The security system triggers if you rob **two adjacent houses** on the same night. Implement `rob(nums)` that returns the maximum amount you can steal **without alerting the police**. Because the houses form a circle, robbing house `0` rules out robbing the last house, and vice versa.
Examples
nums = [2,3,2]→3— You cannot rob houses 0 and 2 (adjacent in the circle), so the best single choice is house 1 = 3.nums = [1,2,3,1]→4— Rob house 0 (1) and house 2 (3) -> 4.nums = [1,2,3]→3— Robbing house 2 alone yields 3.
Constraints
- · 1 <= nums.length <= 100
- · 0 <= nums[i] <= 1000
Session phases
A · Clarify
B · Approach
C · Complexity
D · Edges
E · Code
F · Tradeoff
G · Score
Phase A — Clarify
Ask questions about input bounds, types, and edge constraints.
Ask the coach clarifying questions about the problem.
When you've covered this phase, advance to the next.