• + 0 comments

    Same algorithm in Python:

    def arrayManipulation(n, queries):

    maxVal = -2**32
    arr = [0] * n
    
    for a, b, k in queries:
        arr[a-1] += k
        if(b < n): arr[b] -= k
    
    currSum = 0
    for num in arr:
         currSum += num
         if(currSum > maxVal): maxVal = currSum
    
    return maxVal