Sort game failed test case

this code is for sort-game . it failed one of the test cases due to wrong answer.

@Anushka_Jha Check your custom compare function.
It must be something like this, according to the question
bool mycompare(pair<string,int> p1,pair<string,int> p2)
{
if(p1.second==p2.second)
{
return p1.first<p2.first;
}
return p1.second>p2.second;
}

1 Like

Thank you it passed all the test case but i had a doubt .
i didn’t make any changes to the code and just replaced the code in else of the compare function with “return p1.first<p2.first;” this statement that you mentioned and now it passed all test case so was there any error in the loop i wrote earlier?

There was no need for that loop. Strings can be directly compared instead of comparing it character by character.
Also in the loop, you missed a condition when both the characters are equal.

Thank you my doubt related to this question is solved
but still i have general a query as you mentioned that i missed the condition when both characters are equal but wouldn’t it automatically move to the next iteration if none of the specified conditions are satisfied .as we have already checked for > and < conditions .

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.