Bug Report for https://neetcode.io/problems/maximum-sum-circular-subarray
You need to add one more test to the problem: "[1,-6,-7,4]".
The solution below passes all tests and is "Accepted", but in reality it yields incorrect answer with the following input data: "[1,-6,-7,4]". The right answer would be "5", but it results in "4".
class Solution:
def maxSubarraySumCircular(self, nums: List[int]) -> int:
global_max, global_min = nums[0], nums[0]
cur_max, cur_min = 0, 0
total = 0
for num in nums:
cur_max = max(num, cur_max + num)
cur_min = min(num, cur_min + num)
global_max = max(global_max, cur_max)
global_min = min(global_min, cur_min)
total += num
return max(global_max, total - global_min) if global_max > 0 else global_max
Bug Report for https://neetcode.io/problems/maximum-sum-circular-subarray
You need to add one more test to the problem: "[1,-6,-7,4]".
The solution below passes all tests and is "Accepted", but in reality it yields incorrect answer with the following input data: "[1,-6,-7,4]". The right answer would be "5", but it results in "4".