Java || Simple || Map || Greedy
```\nclass Solution {\n    public String repeatLimitedString(String s, int limit) {\n        int[] map = new int[26];\n        int n = s.length();\n        for 
```\nclass Solution {\n    public String repeatLimitedString(String s, int limit) {\n        int[] map = new int[26];\n        int n = s.length();\n        for (int i = 0; i < n; i++) {\n            map[s.charAt(i) - \'a\']++;\n        }\n        return construct(map, limit);\n    }\n    \n    public String construct(int[] map, int k) {\n        StringBuilder ans = new StringBuilder();\n        for (int i = 25; i >= 0; i--) {\n            while (map[i] != 0) {\n                int same = 0;\n                while (same < k && map[i] > 0) {\n                    ans.append((char)(i + \'a\'));\n                    same++;\n                    map[i]--;\n                }\n                if (map[i] > 0) {\n                    //  brings the next smaller character available\n                    int nse = next(map, i);\n                    if (nse == -1) {\n                        break;\n                    } else {\n                        ans.append((char)(nse + \'a\'));\n                        map[nse]--;\n                    }\n                }\n            }\n        }\n        return ans.toString();\n    }\n    \n    \n    public int next(int[] map, int p) {\n        for (int i = p - 1; i >= 0; i--) {\n            if (map[i] != 0) {\n                return i;\n            }\n        }\n        return -1;\n    }\n}
['Greedy']