• + 1 comment

    function arrayManipulation(n: number, queries: number[][]): number {

    let arr: number[] = Array(n+1).fill(0)
    let max = 0;
    
    queries.forEach((el)=>{
        let a = el[0]
        let b = el[1]
        let k = el[2]
    
        arr[a-1] = arr[a-1] + k
        arr[b] = arr[b] - k
    })
    let sum = 0;
    for (let i = 0; i< arr.length-1; i++){
        sum = sum + arr[i]
        sum > max ? max = sum : null
    }
    return max
    

    }