Only 1 test case is not running. I donâ€™t whatâ€™s the error.
My approach for this problem is:

I have sort the array of strings simply using sort stl 1st.

Then after sorting I am running loop from n1 to 1 if the first alphabet is same then simply check that A[i]>A[i1] and if yess than swap them. For e.g:
if we simply sort the given test case then output will be :
apple
bat
batman
so according to my approach after sorting batman>bat hence I swap these two same upto 1.
But one test case is wrong. Please corresct me where I am wrong.
PS. If there is any other way also to solve this please let me know.