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.
One more optimization can be done: instead of trasversing whole array we could traverse array between indices - lower of left indices and higher of right indices
A psudo code is as follows:
for (i=0;i<row;i++){
if (queries[i][0]-1 < low){
low = queries[i][0]-1;
}
if (queries[i][1]-1 > high){
high = queries[i][1]-1;
}
}
for (i=low;i<=high;i++){
temp += a[i];
if(max < temp){
max = temp;
}
}
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 →
One more optimization can be done: instead of trasversing whole array we could traverse array between indices - lower of left indices and higher of right indices
A psudo code is as follows: