Using set
\n\n# Code\n\nclass Solution {\npublic:\n    string clearStars(string s) \n    {\n        int n = s.length();   \n        string r = "";\n        set<pair<char,
\n\n# Code\n```\nclass Solution {\npublic:\n    string clearStars(string s) \n    {\n        int n = s.length();   \n        string r = "";\n        set<pair<char, int>> st;\n        for(int j = 0; j < n; j++)\n        {\n            if(s[j] == \'*\')\n            {\n                pair<char, int> p = *st.begin();\n                int index = p.second;\n                s[-index] = \'*\';\n                st.erase(st.begin());\n            }\n            else st.insert({s[j], -j});\n        }\n        for(int i = 0; i < n; i++)\n        {\n            if(s[i] != \'*\') r +=  s[i];\n        }\n        return r;\n    }\n};\n```
['Ordered Set', 'C++']