Fastest Python3 Solution! 💯
Complexity
Time complexity: O(n∗log(n))
Space complexity: O(1) (only need to store the characters that are atmost 26)
Code
# Complexity\n- Time complexity: $$O(n*log(n))$$\n- Space complexity: $$O(1)$$ (only need to store the characters that are atmost 26)\n\n# Code\n```python3 []\nclass Solution:\n    def repeatLimitedString(self, s: str, rl: int) -> str:\n        heapq.heapify(chars:= list(map(lambda x: [-ord(x[0]), x[1]], Counter(s).items())))\n        ans = ""\n        while chars:\n            c, f = heapq.heappop(chars)\n            c = chr(abs(c))\n            cf, ff = None, 0\n            ans += c * min(rl, f)\n            f -= rl\n            while f > 0:\n                if ff == 0:\n                    if chars:\n                        cf, ff = heapq.heappop(chars)\n                        cf = chr(abs(cf))\n                    else: break\n                ans += cf + c*min(rl, f)\n                f -= rl\n                ff -= 1\n            if ff:\n                heapq.heappush(chars, [-ord(cf), ff])\n\n        return ans\n\n```
['Python3']