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.
Why are you doing it with interger array? Try it using vector, as given in the question. If you change the format of the answer/method, you are skipping the learning part. Vectors are really very powerful as compared to any other array.
I know this will give you many other troubles like the old 'Segmentation Fault'. But this is what is expected once you are advancing in the programming world.
this can be a way:
vector<int> breakingRecords(vector<int> scores)
{
vector<int> Minmax(2); //VERY CRUCIAL FOR AVOIDING SEGMENTATION FAULT
int i=0;
long long int Min=0, Max=0;
Max = scores.at(i);
Min = scores.at(i);i++;
while (i< scores.size())
{
if(scores.at(i) > Max)
{
Max = scores.at(i);Minmax.at(0)++;
}
else if(scores.at(i) < Min)
{
Min = scores.at(i);Minmax.at(1)++;
}
i++;
}
return(Minmax);
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Breaking the Records
You are viewing a single comment's thread. Return to all comments →
Why are you doing it with interger array? Try it using vector, as given in the question. If you change the format of the answer/method, you are skipping the learning part. Vectors are really very powerful as compared to any other array. I know this will give you many other troubles like the old 'Segmentation Fault'. But this is what is expected once you are advancing in the programming world. this can be a way: