Heap and hashmap for storing indexes
# Complexity\n- Time complexity:\nO(n * logk), where k is number of distinct characters\n- Space complexity:\nO(n)\n# Code\n```python3 []\nclass Solution:\n    def clearStars(self, s: str) -> str:\n        smallest_letters, n = [], len(s)\n        indexes = defaultdict(list)\n        res = []\n        for i in range(n):\n            if s[i] == \'*\':\n                x = heappop(smallest_letters)\n                last = indexes[x].pop()\n                res[last] = \'\'\n                if len(indexes[x]) > 0:\n                    heappush(smallest_letters, x)\n                res.append(\'\')\n            else:\n                if len(indexes[s[i]]) == 0:\n                    heappush(smallest_letters, s[i])\n                indexes[s[i]].append(i)\n                res.append(s[i])\n        \n        return \'\'.join(res)\n\n\n\n\n\n            \n```
['Hash Table', 'Heap (Priority Queue)', 'Python3']