String sort problem

whats error in this code? its not compiling?

hello @nilotpal

check now->

u havent handled all case in ur comparator

if(c==0)

    return s1> s2;//instead of s1.size()>s2.size() the code is correct but what's diffrnt here? can you explain whats happening here?

ss

i have added those else part in your code.
becuase in question it is mentioned that if one string is not a part of another string then in that case we need to sort the strings in lexicographical order (i,e dictionary order)

thats why i did s1 < s2 in the else section

I got that part.

look in this.

thats also correct.

becuase if one string is “abc” and other string is “abcd”
then s1>s2 logic will put “abcd” first and then “abc”

which is equivalent to arranging them in decreasing order of their size

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.