• + 0 comments

    Python Code Implementation Difference Array Instead Brute-Force Method

    `

    def arrayManipulation(n, queries): arr = [0] * (n + 1)
    for a, b, k in queries: arr[a - 1] += k if b < n: arr[b] -= k max_value = 0 current_value = 0 for i in range(n): current_value += arr[i] if current_value > max_value: max_value = current_value

    return max_value
    
    fptr.write(str(result) + '\n')
    fptr.close()
    

    `