I am trying the hackerrank question and they gave said to give the output as "Print two space-separated integers describing the respective numbers of times the best (highest) score increased and the worst (lowest) score decreased." Now, whenever I try to give only cout, it throws an error saying "Non-void function does not return a value". Now normally, I used to give return 0 in these situations but here it is saying "No viable conversion from returned value of type 'int' to function return type." I really don't know how to either return int in a vector function or simply put, how to return the answers back to the compiler.
Here is my function
vector<int> breakingRecords(vector<int> scores) {
int min=0,max=0;
int maxUpdate=0;
int minUpdate=0;
for(int i=0;i<scores.size();i++)
{
if(i==0)
{
min=max=scores[0];
break;
}
if(scores[i]>scores[i-1])
{
max=scores[i];
maxUpdate++;
}
else if(scores[i]<scores[i-1])
{
min=scores[i];
minUpdate++;
}
}
return 0;
}
Note: If my logic has any error then please don't correct it. I want to find errors in my logic on my own just help me get my code run.
The problem is that you set your function to return vector type of object, so returning 0 or not returning anything is unacceptable. You basically have 3 options here:
Good Luck!