• + 2 comments

    I'm not taking the credit. i waste a lot of time with this one too. my js solution, in case someone interested.

    function arrayManipulation(n, queries) {
        let tmp = {},
            max,
            currentNumber = 0;
        for (let i = queries.length - 1; i >= 0; i -= 1) {
            let [firstElem, lastElement, value] = queries[i];
            tmp[firstElem] = (tmp[firstElem] || 0) + value;
            tmp[lastElement + 1] = (tmp[lastElement + 1] || 0) - value;
        }
        for (let key in tmp) {
            currentNumber += tmp[key];
            if (!max || currentNumber > max) {
                max = currentNumber;
            }
        }
        return max;
    }