🔥O(n) || ✅ Min heap || Without Custom Comparator ✅ || C++
Approach\n- Insert char and -1 * index in priority queue.\n- if 2 char are same, we will delete char present at max index means every time pq.top() will give me
# Approach\n- Insert **char** and **-1 * index** in priority queue.\n- if 2 char are same, we will delete char present at max index means every time pq.top() will give me my required element and its index.\n- We simply mark pq.top() element as **\'*\'**.\n- In ans return all the elements of string s which are not **\'***\'.\n\n# Complexity\n- Time complexity: O(n)\n\n\n# Code\n```C++ []\nclass Solution {\npublic:\n    string clearStars(string s) {\n        priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>> pq;\n        for(int i=0;i<s.size();i++){\n            if(s[i]==\'*\'){\n                s[-pq.top().second]=\'*\';\n                pq.pop();\n            }\n            else pq.push({s[i]-\'a\',-i});\n        }\n        string ans="";\n        for(auto& c:s) if(c!=\'*\') ans+=c;\n        return ans;\n    }\n};\n```\n\nDo upvote if you found this useful.\n\n
['String', 'Greedy', 'Heap (Priority Queue)', 'C++']