Why my test case are failing in this string sort

#include <bits/stdc++.h>
using namespace std;
bool compare(string a,string b){
if(a[0]==b[0]){
return a.size()>b.size();
}
return a<b;
}
int main() {
int n;
cin>>n;
string *s=new string[n];
for(int i=0;i<n;i++){
cin>>s[i];

}
sort(s,s+n,compare);
for(int i=0;i<n;i++){
cout<<s[i]<<endl;
}
}

hi @bhardwajsaksham796 send code on ide.codingblocks.com

hi @bhardwajsaksham796 updated https://ide.codingblocks.com/s/672498

whats wrong on this code??

see the change in compare function @bhardwajsaksham796

can u explain the find function what is happening in this case

hi @bhardwajsaksham796,
it checks if a string is present completely as a prefix in another string, then string with longer length should come first

1 Like

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.