• + 1 comment

    I did something pretty similar, just with a little bit more readable forEach:

    const arr = new Array(n).fill(0);
    let result = 0;
    
    queries.forEach(([a, b, k]) => {
        arr[a - 1] += k;
        if (b < arr.length) {
            arr[b] -= k;
        }
    });
    
    arr.reduce((a, b) => {
        const acc = a + b;
        result = Math.max(result, acc);
        return acc;
    }, 0);
    
    return result;