priority queue C++ solution #ACCEPTED😍
class Solution {\npublic:\n\n    string repeatLimitedString(string s, int k) {\n        string ans = "";\n        \n        unordered_mapmp;\n        \n        
class Solution {\npublic:\n\n    string repeatLimitedString(string s, int k) {\n        string ans = "";\n        \n        unordered_map<char , int>mp;\n        \n        for(int i = 0 ; i < s.size() ; i++){\n            mp[s[i]]++;\n        }\n        \n        priority_queue<pair<char , int>>pq;\n        \n        for(auto value : mp){\n            pq.push({value.first ,  value.second});\n        }\n        \n        while(!pq.empty()){\n            char first = pq.top().first;\n            int second = pq.top().second;\n            pq.pop();\n            \n            int size = min(second , k);\n            \n            for(int i = 0 ; i < size ; i++){\n                ans += first;\n            }\n            \n            if(second - k > 0){\n                if(!pq.empty()){\n                    char first2 = pq.top().first;\n                    int second2 = pq.top().second;\n                    pq.pop();\n                    ans += first2;\n                    if(second2 - 1 > 0){\n                        pq.push({first2 , second2 - 1});\n                    }\n                }else{\n                    return ans;\n                }\n                pq.push({first , second - k});\n            }\n        }\n        \n        return ans;\n    }\n};
['C', 'Heap (Priority Queue)']