Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public class ArrayManupilation {
static long arrayManipulation(int n, int[][] queries) {
long[] arr = new long[n+1];
int a, b, k;
for (int [] query : queries) {
a = query[0];
b = query[1];
k = query[2];
arr[a] += k;
if (b+1 <= n) arr[b+1] -= k;
}
long max = 0, x = 0;
for (int i=1 ;i<=n;i++) {
x += arr[i];
if (max < x) {
max=x;
}
}
return max;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.