Easy C++ solution.
Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n    string clearStars(string s) {\n        priority_queu
# Complexity\n- Time complexity: O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    string clearStars(string s) {\n        priority_queue<char, vector<char>, greater<char>> pq;\n        unordered_map<char, stack<int>> stk;\n        for(int i=0;i<s.length();i++){\n          if(s[i]==\'*\'){\n              if(!pq.empty()){\n                char tp=pq.top();\n                stk[tp].pop();\n                if(stk[tp].size()==0){\n                    stk.erase(tp);\n                    pq.pop();\n                }\n              }\n          }\n          else{\n             if(stk.find(s[i])==stk.end()){\n                pq.push(s[i]);\n             }\n             stk[s[i]].push(i);\n          }\n        }\n        vector<pair<int,char>> v;\n        for(auto it:stk){\n            while(!it.second.empty()){\n                v.push_back({it.second.top() , it.first});\n                it.second.pop();\n            }\n        }\n        sort(v.begin(), v.end());\n        string res="";\n        for(auto it:v){\n            string s1(1, it.second);\n            res+=s1;\n        }\n        return res;\n    }\n};\n```
['Stack', 'Sorting', 'Heap (Priority Queue)', 'C++']