String sort problem compare function for sort()

how can i make user defined compare function for this problem ?
can’t get output.

https://codeforces.com/blog/entry/9604
watch this blog to make comparator function