1121. House Robber II (Circular Array)

EasyDynamic Programming1D DP

Houses are arranged in a circle, so the first and last houses are adjacent. Given nums where nums[i] is the money in house i, and you cannot rob two adjacent houses, return the maximum amount you can rob. The input is JSON {nums}.

Input: JSON {nums}.

Output: Integer — the maximum robbable amount.

Examples

Example 1
Input: {"nums":[2,3,2]}
Output: 3
Explanation: Cannot rob both ends; take house 1.
Example 2
Input: {"nums":[1,2,3,1]}
Output: 4
Explanation: Rob houses 0 and 2.
Example 3
Input: {"nums":[1]}
Output: 1
Explanation: Single house.

Constraints

Asked by

MicrosoftBloombergAmazonInfosysGoogleMeta
Solve this problem in the editor →