Python Heap
```\nimport heapq\nfrom collections import Counter\nclass Solution:\n    def sortString(self, s: str) -> str:\n        ctr =Counter(s)\n        res , temp  =[] 
```\nimport heapq\nfrom collections import Counter\nclass Solution:\n    def sortString(self, s: str) -> str:\n        ctr =Counter(s)\n        res , temp  =[] , []\n        for k , v in ctr.items():\n            heapq.heappush(res , (ord(k) , k , v))\n        result = ""\n        while res:\n            while res:\n                cur_val , cur , count = heapq.heappop(res)\n                result+=cur\n                if count -1 > 0:\n                    heapq.heappush(temp , (-cur_val , cur , count-1))\n            while temp:\n                cur_val , cur , count = heapq.heappop(temp)\n                result+=cur\n                if count -1 > 0:\n                    heapq.heappush(res , (-cur_val , cur , count-1))\n        return result
[]