C++ | beats 38% | Priority Queue
Approachso idea is greedy
for a star remove rightmost lowest char to its left
we maintain heap for it with order a<b<c ... and index order in decreasingfor a st


# Approach
<!-- Describe your approach to solving the problem. -->
so idea is greedy
for a star remove rightmost lowest char to its left 
we maintain heap for it with order a<b<c ... and index order in decreasing

for a star we pop and unmark those indices 

in end build answer string of marked characters

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
$$O(n)$$

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

# Code
```cpp []

class Rec {
public:
    char ch;
    int idx;

    Rec(char a, int b) {
        ch = a;
        idx = b;
    }
    bool operator<(const Rec& other) const {
        if (ch != other.ch)
            return ch > other.ch;
        return idx < other.idx;
    }
};

class Solution {
public:
    string clearStars(string s) {
        priority_queue<Rec> pq;
        int n = s.size();
        vector<int> ans(n, 1);

        for (int i = 0; i < n; i++) {
            if (s[i] == '*') {
                // remove
                ans[pq.top().idx] = 0;
                ans[i] = 0;
                pq.pop();
            } else {
                Rec r(s[i], i);
                pq.push(r);
            }
        }
        string s2;
        for(int i = 0; i < n; i++)
            if(ans[i])  
                s2 += s[i];
        
        return s2;
    }
};
```
['C++']