Why Not Stack and Why Heap?
IntuitionImplementation same as standard Monotonic Stack Problem. Read comments. Everything is explained there.Approach

Use a Min-Priority Queue (minPQ) with a
# Intuition
Implementation same as standard Monotonic Stack Problem. Read comments. Everything is explained there.

# Approach
1. Use a Min-Priority Queue (minPQ) with a custom comparator to always store the smallest lexicographical character at the top.If characters are the same, prioritize the rightmost (largest index) character to ensure correct removals.

2. Iterate through the string s. If it's a character, push it into minPQ with its index. If it's a '*', remove the smallest character to its left (top of minPQ) and store its index in a set<int> remove.

3. Build the final result string by skipping characters whose indices are in remove. Keep all other non-'*' characters.

# Complexity
- Time complexity:
O(NlogN)

- Space complexity:
O(N)

# Code
```cpp []
class Solution {
public:
    // Custom comparator for priority queue
    // To achieve a min-priority queue of type pair<char, int> where the smallest character comes first but,
    // in the case of equality of characters, the maximum value of integers is prioritized at the top.
    struct CustomComparator {
        bool operator()(const pair<char, int>& a, const pair<char, int>& b) {
            if (a.first == b.first) {
                // If characters are equal, prioritize the pair with the larger integer
                return a.second < b.second;
            }
            // Otherwise, prioritize the pair with the smaller character
            return a.first > b.first;
        }
    };
    string clearStars(string s) {
        // return lexicographically smallest string.
        // at the end you want to remove all stars
        // and some characters. Store the index of characters to be removed

        // I want a data structure that stores smallest on top and then it gives next smallest.
        // I will not use stack example "dk**" -> it has k to the right of d.
        // Neverthless this method is same as Monotonic stack implementation.

        set<int> remove; // index of characters to be removed in increasing order.
        priority_queue<pair<char, int>, vector<pair<char, int>>, CustomComparator> minPQ;
        char min_char = 'z';
        for(int i = 0; i<s.size(); i++){
            // if it is a char, then push smaller one in stack.
            if(s[i] != '*'){
                minPQ.push({s[i], i});
            }
            else{ // if you encounter '*' then store index of latest smallest character. Then pop it so that next 
            // smallest character(with its index) comes at the top of stack.
                if(!minPQ.empty()){
                    remove.insert(minPQ.top().second);
                    minPQ.pop();
                }
            }
        }
        vector<int> indices(remove.begin(), remove.end()); // contains indices to be removed
        int index = 0;
        string res = "";
        for(int i = 0; i<s.size(); i++){
            if(s[i] != '*'){
                if(index < indices.size() && i == indices[index]){
                    index++;
                    continue;
                }
                else{ // include non '*' char and one whose index is not in indices.
                    res += s[i];
                }
            }
        }
        return res;
    }
};
```
['Heap (Priority Queue)', 'C++']