String sort- 1st question of c++ stl

I don’t understand the logic behind the code given in editorial

how to solve it. the 2 for loops and the next single for loop is not clear to me

Mention problem link