c++ solution using set
\nclass Solution {\npublic:\n    string clearStars(string s) {\n        int n=s.size();\n        vector<bool>visited(n,true);\n        set<pair<char,int>>st;\n 
```\nclass Solution {\npublic:\n    string clearStars(string s) {\n        int n=s.size();\n        vector<bool>visited(n,true);\n        set<pair<char,int>>st;\n        for(int i=0;i<n;i++){\n            if(s[i]==\'*\'&&st.size()){\n                auto [ch,index]=*st.begin();\n                st.erase(st.begin());\n                visited[-index]=false;\n            }\n            else{\n                st.insert({s[i],-i});\n            }\n        }\n        string result="";\n        for(int i=0;i<n;i++)\n        {\n            if(s[i]!=\'*\'&&visited[i]){\n                result+=s[i];\n            }\n        }\n        return result;\n    }\n};\n```
['C', 'C++']