My code is not running for one of the test cases

My code runs for one test case successfully but fails for the other giving a run time error.
Here is my code-

@amanb25 hey apka woh wala case reh rha hai when one string is completely same to other ,also dont apply this approach use stl sort function and make your own comparator,here is pseudo code reference:

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.