String sort challenge

bool compare(string a,string b){
if(a==b){
return a.length()<b.length();
}
return a<b;

}
what wrong i am doing in compare function

This means if “abc” == “abc”
return length which is always equal that’s why they are same

Instead do this


bool compare(string a, string b){
	if(a.size() <= b.size() && b.substr(0, a.size())==a){
       return a.size()>=b.size();
    }
    else if(b.size() <= a.size() && a.substr(0, b.size())==b){
        return a.size()>=b.size();
    }
    else{
        return a<b;
    }
}

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.