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.
// Complete the arrayManipulation function below.
static long arrayManipulation(int n, int[][] queries , int jj) {
long[] a = new long[n+1];
long max=0;
int i=0;
int start = queries[i][0];
int end = queries[i][1];
int sum = queries[i][2];
while(i<jj){
// System.out.println(jj+"=jj"+i);
System.out.println("s"+start+"e"+end+"sum"+sum+"i"+i);
if(start<=end){
a[start]=a[start]+sum;
if(a[start]>max){
max=a[start];
}
System.out.println("start"+start);
start++;
}else{
i++;
if(i<jj){
System.out.println("i"+i);
start = queries[i][0];
end = queries[i][1];
sum = queries[i][2];
}
}
// for(int l=1;l<a.length;l++){
// System.out.print(a[l]+"\t");
Complexity is only O(n) here , right
// }
// System.out.println("");
}
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 →