Skip to content

Bug Report for maximum-sum-circular-subarray #5939

Description

@detkov

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions