Logic explained With Comments || Priority Queue
As we need lexicographically largest string so start adding largest character available.\nOne thing we need to take care of is we cannot repeat a character more
As we **need lexicographically largest string** so start **adding largest character available**.\nOne thing we need to **take care of** is we **cannot repeat a character more than repeatLimit times** so **when this happens** **add 1 next greatest charcter.**\n```\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int repeatLimit) {\n        \n        int n(size(s));\n        vector <int> m(26, 0);\n        for (auto ch : s)   m[ch-\'a\']++;\n        \n        priority_queue <pair<char, int>> pq;\n        for (int i=0; i<26; i++)\n            if (m[i])   \n                pq.push({i+\'a\', m[i]});\n        \n        string res;\n        \n        while (!pq.empty()) {\n\t\t\n            auto top = pq.top(); pq.pop();  // top contains lexicographically greatest character\n            here :\n            int lim = min(top.second, repeatLimit); // lim is number of times top can be added\n            top.second -= lim;\n\t\t\t\n            while (lim--)   res.push_back(top.first);\n            if (top.second > 0) {\n                if (pq.empty()) return res; // if we dont get next greatest character then we cannot use remaining characters so return res\n                auto next = pq.top(); pq.pop(); // next contains lexicographically greatest character smaller than top\n                res.push_back(next.first);\n                next.second -= 1;\n                if (next.second)    pq.push(next);\n                goto here;\n            }\n        }\n        \n        return res;\n    }\n};\n```\n\n**Upvote if it helps :)**
['C', 'Heap (Priority Queue)']