String sort : unexpected output

following is my code for problem STRING SORT

#include<bits/stdc++.h>
using namespace std;

bool cmp(string a,string b)
{
int l1,check=1;
l1=min(a.size(),b.size());
for(int i=0;i<l1;i++)
{
if((a[i])!=(b[i]))
{
check=0;
break;
}
}

if(check)
return a>b;
else
return a<b;}

int main() {
int n;
string s[1000];
cin>>n;

for(int i=0;i<n;i++)
{
	cin>>s[i];
}

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

return 0;

}

PROBLEM: on submission i got 100/100,
but for input like
4
bat
batmam
batmanplayer
apple

output:
apple
batmam
batmanplayer
bat

but , batmanplayer should occur before batman . can you help to figure out logical mistake (if any).

What you should do in compare function is that

  1. First check character by character until the length of smaller string. Return wherever you get unequal.
  2. If all are equal, then return the string which is having larger length.

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.