FastPrepHouse Robber II

House Robber II

Apple logoApple● MediumFULLTIMEOA
Learn

Problem statement

Houses stand in a circle, and nums[i] is the nonnegative money in house i. The first and last houses are neighbors. Robbing two neighboring houses triggers an alarm.

Return the maximum total money you can rob without triggering an alarm. You may skip every house. With one house, you may rob that house once. Only the maximum amount matters, regardless of which optimal set achieves it.

Function

robCircular(nums: int[]) → int

Examples

Example 1

nums = [2,3,2]return = 3

The two houses holding two are adjacent around the circle, so only the middle house is optimal.

Example 2

nums = [1,2,3,1]return = 4

Choose the houses holding one and three.

Example 3

nums = [0]return = 0

The only house contains no money.

Constraints

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

More Apple problems

See Apple hiring insights
public int robCircular(int[] nums) {
    // Write your solution here.
}
nums[2,3,2]
expected3
Checking account…