Skip to content

Instantly share code, notes, and snippets.

@ytnk531
Last active August 18, 2018 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ytnk531/084b9ef3bb268f0a305e0825384a88f4 to your computer and use it in GitHub Desktop.
Save ytnk531/084b9ef3bb268f0a305e0825384a88f4 to your computer and use it in GitHub Desktop.
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