You are viewing a single comment's thread. Return to all comments →
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;
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 did something pretty similar, just with a little bit more readable forEach: