One test case couldn't pass

@gaganpreetsachdev1, your code is not correct
check this test case
3
c
a
b

correct ans:-
a b c
your ans :-
b a c

in my compiler its giving a b c only please check and tell me where exactly the error is

@gaganpreetsachdev1,yeah that was my bad i changed your code before testing,
the problem in your code is that you are only checking the first character and if they don’t match you sort lexiographically but what if you have some thing like
3
aac
aad
aae

your output :-
aae aad aac
inside your comparator function you will always get index as 1 as for any two strings character matches till i=1 thus making index=1; so your check function will always return 1 and place a before b and you get wrong answer,

what you need to do inside your comparator(a,b) is check for every index value between (0,min(a.size(),b.size())-1) if at any index the characters do not match then return lexiographically , else if loop ends means that one of them is prefix of other in that case return according to size

refer this code :- https://ide.codingblocks.com/s/241662

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.