822. House Robber II
0
Medium
As a professional robber, you are planning to rob houses along a street. Each house contains a certain amount of money. The houses are arranged in a circle, meaning the first house is adjacent to the last one. However, adjacent houses have a security system that will alert the police if two adjacent houses are robbed on the same night.
Given an integer array nums representing the amount of money in each house, your task is to determine the maximum amount of money you can rob tonight without triggering the security system.
Input Format
The first line of input contains an integer N, representing the size of the array.
The second line contains N space-separated integers, describing the money in each house.
Output Format
Print the maximum amount of money you can rob tonight without alerting the police.
Example
Input
3
2 3 2
Output
3
Constraints
1 <= N <= 100
0 <= nums[i] <= 1000
0 <= nums[i] <= 1000
Loading...
View Submissions
Console