Python3 | Simple stack without heap
After investigation, we found if there is a smallest char, delete it from the rightmost of the current string would keep the current string as lexicographically
After investigation, we found if there is a smallest char, delete it from the rightmost of the current string would keep the current string as lexicographically minimum string. We can use a stack to track the index of each character and pop from it to get the rightmost index.\n\nHence when traverse the string, we use following variable\n-  `char_index` to record the index occrance of each character\n- `smallest_c` to record the  smallest character so far\n- `current_s` to record all the character and set the deleted character as `\'\'` so that we can join them to get the anwser in the end\n\nTC `O(n)` the `for` loop iterate the length of string times\nSC `O(n)` the `current_s` record at most the length of string elements\n\n```\nclass Solution:\n    def clearStars(self, s: str) -> str:\n\n\t\t# use list to mutate char\n        current_s = [] \n        smallest_c = \'\'\n        char_index = defaultdict(list)\n\n        for i in range(len(s)):\n            c = s[i]\n            \n            current_s.append(c)\n            if c != \'*\':\n                if not smallest_c or ord(c) < ord(smallest_c):\n                    smallest_c = c\n\n                char_index[c].append(i)\n            else:\n                index = char_index[smallest_c].pop()\n                current_s[index] = \'\'\n\n\t\t\t\t# update smallest_c when there is no more the original one \n                if len(char_index[smallest_c]) == 0:\n                    del char_index[smallest_c]\n                    \n                    keys = char_index.keys()\n\n                    if keys:\n                        smallest_c = min(keys)\n                    else:\n\t\t\t\t\t\t# reset smallest_c to \'\' so that we can set it to another one later\n                        smallest_c = \'\'\n        return \'\'.join(\'\' if c == \'*\' else c for c in current_s)\n                \n```
['Stack', 'Python3']