Solution Using Priority Queue 🔥✅
Store the pair of {char , index} in the queue on the basis of character such that, character with lowest value and higher index should be given more priority\n2
1. Store the pair of {char , index} in the queue on the basis of character such that, character with lowest value and higher index should be given more priority\n2. we maintained a Cmp to store elements in queue\n3. Vis vector is used to mark the indexes which is removed from the from the string\n4. After that, Just Traverse the string\n5. Use string ans="" to return the result\n5. vis[i] == false and It is not equal to \'*\' just add it in ans\n6. return ans.\nPlease Upvote if You like Thank you :)\nKeep Coding\n\n# Code\n```\nclass Solution {\npublic:\n    struct Cmp {\n    bool operator()(const pair<char, int>& a, const pair<char, int>& b) const {\n        if (a.first != b.first) {\n            return a.first > b.first;\n        }\n        return a.second < b.second;\n    }\n};\n\n// void printPriorityQueue(priority_queue<pair<char, int>, vector<pair<char, int>>, Compare> pq) {\n//     while (!pq.empty()) {\n//         pair<char, int> e = pq.top();\n//         pq.pop();\n//         cout << "(" << e.first << "," << e.second << ") ";\n//     }\n//     cout << endl;\n// }\n\n\n    string clearStars(string s) {\n        priority_queue<pair<char, int>, vector<pair<char, int>>, Cmp> pq;\n        int n=s.size();\n        vector<int> vis(n,false);\n        for (int i = 0; i < n; i++) {\n            if(s[i] == \'*\'){\n                auto p = pq.top();\n                pq.pop();\n                char ch = p.first;\n                int id = p.second;\n                vis[id] = true;\n            }\n            else{\n                pq.push({s[i], i});\n            }\n        }\n\n        string ans="";\n\n        for(int i=0;i<n;i++){\n            if(!vis[i] && s[i] != \'*\'){\n                ans+=s[i];\n            }\n        }\n\n    return ans;\n\n    }\n};\n```
['Heap (Priority Queue)', 'C++']