House Robber in a Circle

Given a circular street of houses, return the maximum amount you can rob without robbing adjacent houses. Pattern focus: Take Or Skip DP. Because the first and last houses are adjacent, solve two linear cases and take the maximum.

Input Format

nums = money in circular 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 result comes from robbing the middle houses.

Loading...
House Robber in a Circle - Dp 1d DSA Problem