We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
/* Any ideas of why my code is leading up to a large execution time. Thank you in advance */
function arrayManipulation(n, queries) {
if (n > 10 ** 7) {
n = 10 ** 7
};
if (queries.length > 2 * (10 ** 5)){
queries.length = 2 * (10 ** 5)
};
let array = [];
array.length = n
// value/ start / end
array.fill(0, 0, n)
let result = 0;
queries.forEach((e)=> {
let a = e[0] - 1; // queries[y][0]
let b = e[1] - 1; // queries[y][1]
let k = e[2]; // queries[y][2]
for (let i = a; i <= b; i++) {
// add k to the values between array[i] && array[i]
array[i] = array[i] + k;
}
})
result = Math.max(...array)
return result
}
Cookie support is required to access HackerRank
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 →
/* Any ideas of why my code is leading up to a large execution time. Thank you in advance */
function arrayManipulation(n, queries) {
}