You are viewing a single comment's thread. Return to all comments →
JS:
function arrayManipulation(n, queries) {
let arr = Array(n+1).fill(0); // console.log("arr: ", arr); for(let [a,b,k] of queries){ arr[a-1] = arr[a-1] + k; arr[b] = arr[b] - k; } let acc = 0; let result = 0; arr.forEach(el=> { acc = acc+el; result = Math.max(result, acc) }) // console.log(result); return result; // ! end of function
}
let n1 = 5; // length of the array let queries1 = [ [ 1, 2, 100 ], [ 2, 5, 100 ], [ 3, 4, 100 ] ]; // number of queries
arrayManipulation(n1, queries1);
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:
function arrayManipulation(n, queries) {
}
let n1 = 5; // length of the array let queries1 = [ [ 1, 2, 100 ], [ 2, 5, 100 ], [ 3, 4, 100 ] ]; // number of queries
arrayManipulation(n1, queries1);