String sort STL challenge

Can’t figure out how to solve the error.
Code-

hello @PranavM16

ur comparator is wrong.

u need to check if one string is prefix of other or not.
if it is then sort in descending order of length .
otherwise sort in lex order

Ok. I’ll try to change it. But it is also giving compile time error in sort function. Can you help with that? @aman212yadav

pls share ur updated code with me

I haven’t updated the code yet, I was talking about the original code that I sent above ^

check now->

1 Like

My updated code is also giving correct answer. Can you check? @aman212yadav

Updated code-

check now->

Can you also add some comments to explain the if statements and the return statements? I did not understand the logic. Mainly for the return statements @aman212yadav

if one string is prefix of other then string with larger size should come first and then smaller string right?

return a.size() > b.size() ; // is doing the same thing. i,e this line is telling that first string should have bigger lenght compare to second string.

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.

1 Like