Standard Bar Dynamic Programming · 1D DP O(n) · O(1)
The bot's next assignment is a circular storage ring where bay 0 sits beside the final bay, closing the alarm circuit into a loop. Cracking both ends of the ring in one shift is impossible. The dispatcher wants the maximum haul across all legal subsets, so the planner breaks the ring into two straight corridors — with and without the first bay — and takes the better result.
Input: An array nums of n non-negative integers arranged in a circle, where nums[i] is the charge in bay i.
Output: Return the maximum total charge collectable when no two adjacent bays (including the first and last) are opened.
1 <= n <= 1000 <= nums[i] <= 1000Input: {"nums":[2,3,2]}
Output: 3
Bays 0 and 2 are now neighbors, so only one of them can be taken — best is bay 1 alone for 3.
Input: {"nums":[1,2,3,1]}
Output: 4
The ring splits into [2,3] (answer 3) and [1,3,1] (answer 4); take 4.