O(n) two pointer approach in Go
IntuitionUse two pointers to track the current lex max rune and the next one, if the current one reaches repeatLimit, append the next one, in a loopApproachUse
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nUse two pointers to track the current lex max rune and the next one, if the current one reaches repeatLimit, append the next one, in a loop\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nUse strings.Repeat for constructing strings consist of the same character in constant time.\nUse strings.Builder for constant time string construction.\n\n# Complexity\n- Time complexity: O(n)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```golang []\nfunc repeatLimitedString(s string, repeatLimit int) string {\n    counts := make([]int, 26)\n\n    for _, c := range s {\n        counts[int(c-\'a\')]++\n    }\n\n    i, j := 25, 25\n    var sb strings.Builder\n\n    for j >= 0 {\n        if i == j || (i >= 0 && counts[i] == 0) {\n            i--\n            continue\n        }\n\n        if counts[j] == 0 {\n            j--\n            continue\n        }\n\n        count := min(repeatLimit, counts[j])\n        counts[j] -= count\n        sb.WriteString(strings.Repeat(string(\'a\' + j), count))\n\n        if i < 0 {\n            break\n        }\n\n        if counts[j] > 0 {\n            sb.WriteRune(rune(\'a\' + i))\n            counts[i]--\n        } else {\n            j = i\n        }\n    }\n\n    return sb.String()\n}\n```
['Go']