String sort question approach

Please let me know the approach to this question. Also , can this be done using custom sort function ( using compare ) ?

sort the strings and then according to the first character sort using whose length is bigger.
actually the question is that if two strings have same prefix , then sort according to the length in decreasing order

I think this approach wont work because if there are two strings say " bee " and " bfsuy " . Then normal sorting gives the order - "bee ", "bfsuy " . After that according to your approach , if I consider only the first character and sort on the basis of length , then the order would become - " bfsuy ", "bee " , which is wrong . I think the q. says whenever one string is prefix of other then we should follow the rule of decreasing length. Please clarify this.

try and submit from both the approaches, see when you get the AC.

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.