c++ faster = and less memory than 90% with explanation
Intuition\n Describe your first thoughts on how to solve this problem. \n        1. construct a map\n        2. then build a string using largest char first, wi
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n        1. construct a map\n        2. then build a string using largest char first, with in repeatlimit.\n        3. if reach limit, insert a second largest char and continue try using largest char\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```\nclass Solution {\npublic:\n    string repeatLimitedString(string s, int repeatLimit) {\n        // construct a map\n        vector<int> map(26,0);\n        for (char c : s)\n            map[c-\'a\']++;\n\n        // then build a string using largest char first, with in repeatlimit.\n        // if reach limit, insert a second largest char and continue try using largest char\n        string res;        \n        for(int i = 25; i>=0; i--)\n        {\n            while (map[i] > 0)\n            {\n                for (int k = 0; k < min(map[i], repeatLimit); k++)\n                    res+= \'a\'+i; \n                \n                bool con = false;\n                map[i]-=min(map[i], repeatLimit);\n                if (map[i] > 0)\n                {\n                    for (int j = i-1; j>=0; j--)\n                    {\n                        if(map[j] > 0)\n                        {\n                            res += \'a\'+j;\n                            map[j] --;\n                            con = true;\n                            break;\n                        }\n                    }\n                }\n                if (!con)\n                    break;\n            }\n        }\n        return res;        \n    }\n};\n```
['C++']