• + 0 comments

    JS implementation of your algorithm:

    const arr = [0];
    for (let i = 1; i <= n; ++i) arr[i] = 0;
    
    queries.forEach(query => {
        const [a, b, k] = query;
        arr[a] += k;
        if (b + 1 < arr.length) arr[b+1] -= k;
    });
    
    const {x, max} = arr.reduce((acc, current) => {
        acc.x += current;
        acc.max = Math.max(acc.max, acc.x);
        return acc;
    }, {x: 0, max: -Infinity});
    
    return max;