House Robber II

Given an array nums representing houses in a circle, return the maximum amount you can rob without robbing adjacent houses. Pattern focus: House robber. The circular condition means you must exclude either the first house or the last house.

Input Format

nums = money in circularly arranged houses

Output Format

maximum amount that can be robbed

Constraints

  • 1 <= nums.length <= 10^5; 0 <= nums[i] <= 10^9

Examples

Example 1:

Input:

nums = [2,3,2]

Output:

3

Explanation:

You cannot rob both the first and last houses.

Example 2:

Input:

nums = [1,2,3,1]

Output:

4

Explanation:

The best plan is to rob houses 2 and 4.

Loading...
House Robber II - Dp 1d DSA Problem