451. Sort Characters By Frequency
https://leetcode.com/problems/sort-characters-by-frequency/description/
class Solution { public: string frequencySort(string s) { map<char,int> m; for (auto c : s) m[c]++; priority_queue<pair<int,char>> q; for (const auto& f : m) q.push( {f.second, f.first} ); string res; while (!q.empty()) { res += string(q.top().first, q.top().second); q.pop(); } return res; } };