EASY SOLUTION USING HEAP FOR BEGINNER'S!!!
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution\n{\npublic:\n    string repeatLimitedString(string s, int repeatLimit)\n    {\n        priority_queue<pair<char, int>> pq;\n        map<char, int> mp;\n        for (auto &it : s)\n        {\n            mp[it]++;\n        }\n        for (auto it : mp)\n        {\n            pq.emplace(it.first, it.second);\n        }\n        string ans;\n        while (!pq.empty())\n        {\n            auto it = pq.top();\n            pq.pop();\n            char ch = it.first;\n            int cnt = it.second;\n            int use = min(cnt, repeatLimit);\n            ans.append(use, ch);\n            cnt -= use;\n            if (cnt > 0)\n            {\n                if (!pq.empty())\n                {\n                    auto sc = pq.top();\n                    pq.pop();\n                    char nextChar = sc.first;\n                    int nextCnt = sc.second;\n                    ans.push_back(nextChar);\n                    nextCnt--;\n                    if (nextCnt > 0)\n                    {\n                        pq.emplace(nextChar, nextCnt);\n                    }\n                }\n                else\n                {\n                    break;\n                }\n                pq.emplace(ch, cnt);\n            }\n        }\n        return ans;\n    }\n};\n\n```\n\n
['Heap (Priority Queue)', 'C++']