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.
public static long arrayManipulation(int n, List> queries) {
int row=queries.size();
int col=queries.get(0).size();
//array to hold final combine result from row:0 to row:n
long[] arr = new long[n];
long max=0, currMax=0;
for(int i=0; i<row; i++) {
int start=queries.get(i).get(0);
int end=queries.get(i).get(1);
int val=queries.get(i).get(2);
for(int j=start-1; j<end; j++) {
arr[j]=arr[j]+val;
if(arr[j]>currMax){
currMax=arr[j];
}
}
if(currMax>max){
max=currMax;
}
}
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 →
Java working solution, with some test cases are failing because of "time limit exceed"
#########################################################################public static long arrayManipulation(int n, List> queries) { int row=queries.size(); int col=queries.get(0).size(); //array to hold final combine result from row:0 to row:n long[] arr = new long[n]; long max=0, currMax=0;
#