1746. Maximum Subarray Sum After One Operation

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 1746

class Solution:
    def maxSumAfterOperation(self, nums: List[int]) -> int:
        f = g = 0
        res = -inf
        for x in nums:
            ff = max(f, 0) + x
            gg = max(max(f, 0) + x * x, g + x)
            f, g = ff, gg
            res = max(res, f, g)
        return res