Priority Queue || Max Heap || Map || C++
\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int r) {\n        unordered_map<char,int>mp;\n        for(auto c:s)\n        {\n          
```\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int r) {\n        unordered_map<char,int>mp;\n        for(auto c:s)\n        {\n            mp[c]++;\n        }\n        // Keep the characters and it\'s count in max heap, Charater as first element\n        priority_queue<pair<char,int>>pq;\n        for(auto p:mp)\n        {\n            pq.push(p);\n        }\n        string ans;\n        // For each top element, if it has occurance greater or equal to repeatLimit than take this character repeatLimit times \n        while(!pq.empty())\n        {\n            auto [c,f]=pq.top();\n            pq.pop();\n            for(int i=0;i<r and f>0;i++)\n            {\n                ans+=c;\n                f--;\n            }\n            // if frecuency of current charater>repeatLimit\n            if(f)\n            {\n                // than check if there is any element in heap so that we can take that \n                if(!pq.empty())\n                {\n                    auto p=pq.top();\n                    pq.pop();\n                    ans+=p.first;\n                   if(p.second-- >1)\n                   {\n                       pq.push(p);\n                   }\n                pq.push({c,f}); \n                }\n\t\t\t\t// otherwise if this was the last element that return from here\n                else\n                {\n                    return ans;\n                }\n            }\n            \n        }\n        return ans;\n    }\n};\n```
[]