priority_queue solution
Complexity

Time complexity:O(Nlogn)


Space complexity:

Code


# Complexity
- Time complexity:O(Nlogn)

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    struct Compare {
        bool operator()(const pair<char, int>& a, const pair<char, int>& b) {
            if (a.first != b.first)
                return a.first > b.first;
            return a.second < b.second;
        }
    };
    string clearStars(string s) {
        unordered_map<int, int> m;
        priority_queue<pair<char, int>, vector<pair<char, int>>, Compare> pq;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] == '*') {
                cout << i << " ";
                m[pq.top().second]++;
                pq.pop();
            } else {
                pq.push({s[i], i});
            }
        }
        string ss;
        for (int i = 0; i < s.size(); i++) {
            if (m.find(i) == m.end() && s[i] != '*') {
                ss += s[i];
            }
        }
        return ss;
    }
};
```
['String', 'Greedy', 'Heap (Priority Queue)', 'C++']