Regarding string sort


how the int compare function works in this problem

you are making the code too complex. all you need to do in this question is to write an custom comparator function. If one string is prefix of other then compare on the basis of length else compare on the basis of lexicographical order
Code