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.
Java
int array [ ] = new int[n];
for(List operation: operations){
int a = operation.get[0]-1;
int b = operation.get[1]-1;
int k = operation.get[2];
for(int i=a; i<=b; i++){
array[i]+= k;
}
}
int sum =0;
for(int i=0 i<n; i++){
sum+= array[i];
}
return Math.round(sum/n);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Filling Jars
You are viewing a single comment's thread. Return to all comments →
Java int array [ ] = new int[n]; for(List operation: operations){ int a = operation.get[0]-1; int b = operation.get[1]-1; int k = operation.get[2]; for(int i=a; i<=b; i++){ array[i]+= k; } }