• + 0 comments
    function arrayManipulation(n, queries) {
        // Write your code here
        const arr = new Array(n).fill(0);
        let max = 0;
        
        for(let i = 0; i < queries.length; i++) {
            const [a,b,k] = queries[i];
            
            // -1 because arrays are indexed 0, but a & b constraints 1<=a<=b<=n
            for(let j = a - 1; j <= b - 1 ; j++) {
                arr[j] += k;
    
                max = Math.max(arr[j], max);
            }
        }
        
        return max;
    }