Python | Straightforward Solution | Counting
We store the frequency of each character of the string in an array(A[26]). Now we start from the last index of the array which will store z as we need to genera
We store the frequency of each character of the string in an array(A[26]). Now we start from the last index of the array which will store z as we need to generate output in lexiographically increasing order.\n\n```\n    def repeatLimitedString(self, s: str, repeatLimit: int) -> str:\n        arr = [0] * 26\n        a = ord(\'a\')\n        \n        for char in s:\n            arr[ord(char)-a] += 1\n\t\t\t\n        # Using an array to store the answer as appending to a string is a costly operation\n        ans = []\n        curr = 25\n        prev = 24 \n\t\t\n        # We are starting with curr = 25 as we need to add the largest character first\n        while curr >= 0:\n            if arr[curr] == 0:\n                curr -= 1\n                continue\n            \n\t\t\t# If the character is present in the string then we add it to our answer \n            for i in range(min(repeatLimit, arr[curr])):\n                ans.append(chr(curr + a))\n                arr[curr] -= 1\n                \n\t\t\t# If the above for loop was able to add all the characters then we can move on to the next one\n            if arr[curr] == 0:\n                curr -= 1\n                continue\n            \n\t\t\t# If the above for loop was not able to add all the characters then we need to add a second largest character before we can continue  adding the largest character to our answer again\n            g = False\n            for j in range(min(prev, curr-1), -1, -1):\n                if arr[j]:\n                    g = True\n                    arr[j] -= 1\n                    prev = j\n                    ans.append(chr(j+a))\n                    break\n\t\t\t# If g is false then we know that there were no other characters present other  than the largest character\n            if not g: break\n            \n        return \'\'.join(ans)\n```
[]