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.
static long ArrayManipulation(int n, int[][] queries) {
var additions = new long[n + 1];
foreach (var query in queries) {
var start = query[0];
var end = query[1];
var valueToAdd = query[2];
additions[start] += valueToAdd;
if (end + 1 < additions.Length)
additions[end + 1] -= valueToAdd;
}
long sum = 0;
long max = 0;
for (var x = 1; x < additions.Length; x ++) {
sum += additions[x];
max = sum > max ? sum : max;
}
return max;
}
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 →
Similar solution in C#: