Medium

Quiz

#213 House Robber II

APPROACH

Houses sit in a circle, so the first and last are neighbors. A shared alarm fires if any two adjacent houses are burglarized the same night.

Given an integer array nums with the cash in each house, return the most money you can steal without setting off the alarm.

Example 1:

Input: nums = [2,3,2]
Output: 3
Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.

Example 2:

Input: nums = [1,2,3,1]
Output: 4
Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
Total amount you can rob = 1 + 3 = 4.

Example 3:

Input: nums = [1,2,3]
Output: 3
1 of 4
1:00

What is the optimal approach for this problem?