2 solutions [array] + [maxHeap]
Code
\n# Code\n```golang [Using Array]\nfunc repeatLimitedString(s string, repeatLimit int) string {\n\n\tfreq := make([]int, 26)\n\n\tfor i := 0; i < len(s); i++ {\n\t\tfreq[s[i]-\'a\']++\n\t}\n\n\tindex := 25\n\tresult := []byte{}\n\n\tfor index >= 0 {\n\t\tif freq[index] == 0 {\n\t\t\tindex--\n\t\t\tcontinue\n\t\t}\n\n\t\tk := min(repeatLimit, freq[index])\n\n\t\tfor i := 0; i < k; i++ {\n\t\t\tresult = append(result, byte(index+\'a\'))\n\t\t}\n\n\t\tfreq[index] -= k\n\t\tlettersLeft := freq[index]\n\t\tif lettersLeft > 0 {\n\t\t\tprevIndex := index - 1\n\n\t\t\tfor prevIndex >= 0 && freq[prevIndex] == 0 {\n\t\t\t\tprevIndex--\n\t\t\t}\n\n\t\t\tif prevIndex == -1 {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tresult = append(result, byte(prevIndex+\'a\'))\n\t\t\tfreq[prevIndex]--\n\t\t}\n\n\t}\n\n\treturn string(result)\n}\n\n```\n\n```golang [Using MaxHeap]\ntype pair struct {\n\tchar  byte\n\tcount int\n}\n\ntype maxHeap []pair\n\nfunc (h maxHeap) Len() int           { return len(h) }\nfunc (h maxHeap) Less(i, j int) bool { return h[i].char > h[j].char }\nfunc (h maxHeap) Swap(i, j int)      { h[i], h[j] = h[j], h[i] }\n\nfunc (h *maxHeap) Pop() any {\n\told := *h\n\tn := len(old)\n\titem := old[n-1]\n\t*h = old[:n-1]\n\treturn item\n}\n\nfunc (h *maxHeap) Push(x any) {\n\t*h = append(*h, x.(pair))\n}\n\nfunc repeatLimitedString(s string, repeatLimit int) string {\n\tresult := []byte{}\n\tfreq := map[byte]int{}\n\n\tfor i := 0; i < len(s); i++ {\n\t\tfreq[s[i]]++\n\t}\n\n\th := maxHeap{}\n\n\tfor char, count := range freq {\n\t\th = append(h, pair{char: char, count: count})\n\t}\n\n\theap.Init(&h)\n\n\tfor len(h) > 0 {\n\t\tcurrentPair := heap.Pop(&h).(pair)\n\n\t\tk := min(currentPair.count, repeatLimit)\n\n\t\tfor i := 0; i < k; i++ {\n\t\t\tresult = append(result, currentPair.char)\n\t\t}\n\t\tcurrentPair.count -= k\n\n\t\tif currentPair.count > 0 {\n            if len(h)==0{\n                break\n            }\n\t\t\t//add a separator\n\t\t\tnextPair := heap.Pop(&h).(pair)\n\t\t\tresult = append(result, nextPair.char)\n\t\t\tnextPair.count--\n            if nextPair.count>0{\n               heap.Push(&h, nextPair)\n            }\n\t\t\theap.Push(&h, currentPair)\n\t\t}\n\t}\n\n\treturn string(result)\n}\n\n```
['Go']