• + 0 comments

    Best solution right here. I was able to brute force it but a few test cases were failing. I implemented your aglorithm in Go and it works great. All test cases passing.

    func arrayManipulation(n int32, queries [][]int32) int64 {
        var max int64
        var arr = make([]int64, n)
        
        for _, q := range queries {
            a, b, k := q[0], q[1], int64(q[2])
    
            arr[a-1] += k
            if b < n { arr[b] -= k }
        }
    
        var sum int64
        for _, n := range arr {
            sum = sum + n
            if sum > max { max = sum }
        }
    
        return max
    }