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) {
long[] arr = new long[n];
long max=0;
int a=0; int b=0; int k=0;
int m=queries.length;
for (int i=0; i<m; i++){
a = queries[i][0]-1;
b = queries[i][1]-1;
k = queries[i][2];
arr[a]+=k;
if(b+1<n)
arr[b+1]-=k;
}
for (int i=1;i<n;i++ ){
arr[i]+=arr[i-1];
if (arr[i]>max)
max=arr[i];
}
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 →
Too good!
Same solution in java: