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.
long arrayManipulation(int n, vector> queries) {
long res[n], max=0;
if(n>0){
for(int i = 0; i<n; i++) res[i]=0;
}
else{
return -1;
}
if(!queries.empty()){
int rowSize=queries.size(), colSize=queries[0].size();
if(colSize>=2){
for(int i=0; i<rowSize; i++){
if(queries[i][0]>0 && queries[i][1]>=queries[i][0]){
for(int m = queries[i][0] ; m<=queries[i][1] && m<n ; m++){
res[m] += queries[i][2];
}
}
}
}
if(n){
max =res[0];
for (int i =1; i<n; i++) {
if(max<res[i]){
max = res[i];
}
}
}
}
return max;
}
But only 8/16 TCs are passing. 7/16 TCs are failing with segmentation fault. 1 TC is failing with the wrong answer.
I cannot figure it out which part of the code is causing the segmentation fault. Can anyone help?
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 →
This is the solution for my code:
long arrayManipulation(int n, vector> queries) { long res[n], max=0;
}
But only 8/16 TCs are passing. 7/16 TCs are failing with segmentation fault. 1 TC is failing with the wrong answer. I cannot figure it out which part of the code is causing the segmentation fault. Can anyone help?