#include #include #include #include using namespace std; class Solution { public: string rankTeams(vector& votes) { unordered_map list; for(auto i : votes){ for(int j = 0;j < i.size();j++){ list[i[j]] += i.size() - j; } } string res; vector> temp(list.begin(),list.end()); stable_sort(temp.begin(),temp.end(),[](pair a,pair b){ return a.second > b.second; }); for(auto i : temp){ res += i.first; } return res; } }; int main(){ vector votes = {"WXYZ","XYZW"}; Solution s; cout << s.rankTeams(votes) << endl; return 0; }