You are viewing a single comment's thread. Return to all 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;
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 →
JS implementation of your algorithm: