• + 0 comments

    Python 3: You can solve this problem efficiently by using a technique called "prefix sum" or "cumulative sum

    def arrayManipulation(n, queries):
        arr = [0] * (n + 1)
        for query in queries:
            a, b, k = query
            arr[a - 1] += k
            arr[b] -= k
    
        max_value = 0
        current_sum = 0
    
        for value in arr:
            current_sum += value
            max_value = max(max_value, current_sum)
    
        return max_value