You are viewing a single comment's thread. Return to all 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; }
Seems like cookies are disabled on this browser, please enable them to open this website
Array Manipulation
You are viewing a single comment's thread. Return to all comments →
I'm not taking the credit. i waste a lot of time with this one too. my js solution, in case someone interested.