House Robber II (Circular)
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
A row of houses is arranged in a **circle**, so the first house and the last house are direct neighbors. Each house holds some amount of cash, given in an integer array nums where nums[i] is the money stashed in house i.
You are planning a single night of break-ins, but there is a catch: the security systems of any two **adjacent** houses are linked, and robbing two neighboring houses on the same night triggers an alarm. Because the layout is circular, house 0 and house n - 1 count as adjacent in addition to the usual side-by-side pairs.
Return the **maximum** total amount of money you can rob without ever hitting two adjacent houses.
Since house 0 and house n - 1 can never both be robbed, the circular problem reduces to two independent linear sub-problems: rob from the houses nums[0 .. n-2] (skip the last) or from nums[1 .. n-1] (skip the first), and take the better result.
Examples
Constraints
- 1 <= nums.length <= 100
- 0 <= nums[i] <= 1000
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.