• + 2 comments

    Can you help me see what is wrong with my code here?

    func arrayManipulation(n int32, queries [][]int32) int64 {
        a := make([]int64, n + 1)
        qLen := len(qs)
        for i:=0; i<qLen; i++ {
            p := int(qs[i][0])
            q := qs[i][1]
            sum := int64(qs[i][2])
            a[p] += sum
            if((q + 1) <= n) {
                a[q + 1] -= sum
            }
        }
    
        var x, max int64 = 0, 0
        for i:=1; i<=int(n); i++ {
            x += a[i]
            if max < x {
                max = x
            }
        }
    
        return max
    
    }