Problem · Dynamic Programming
Maximum Value from Circular Houses
Learn this problemProblem statement
Houses stand in a circle. The nonnegative integer nums[i] is the value available in house i. Select houses with no two adjacent and return the maximum total value.
The first and last houses are adjacent. For this exercise, assume there is at least one house, selecting none is allowed, and a single house may be selected.
Function
robCircular(nums: int[]) → intExamples
Example 1
nums = [2,3,2]return = 3The two houses worth 2 are adjacent around the circle, so choose the middle house worth 3.
Example 2
nums = [1,2,3,1]return = 4Choose values 1 and 3 at indices 0 and 2; they are not adjacent.
Example 3
nums = [5]return = 5The only house may be selected.
Constraints
1 <= nums.length <= 10^5.0 <= nums[i] <= 10^4.- The result fits in a signed 32-bit integer.