Easy C++ | Store Prefix Alphabets index | Linear Time | Lexicographically Minimum String
\n# Complexity\n- Time complexity: O(n)\n Add your time complexity here, e.g. O(n) \n\n- Space complexity: O(n)\n Add your space complexity here, e.g. O(n) \n\n
\n# Complexity\n- Time complexity: $$O(n)$$\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: $$O(n)$$\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    string clearStars(string s) {\n        vector<vector<int>> cnt(26, vector<int>(0));\n        for(int i = 0; i<s.size(); i++){\n            if(s[i] == \'*\'){\n                for(int j = 0; j<26; j++){\n                    if(cnt[j].size() > 0){\n                        s[cnt[j].back()] = \'0\';\n                        cnt[j].pop_back();\n                        break;\n                    }\n                }\n            }else{\n                int index = s[i] - \'a\';\n                cnt[index].push_back(i);\n            }\n        }\n\n        string ans = "";\n        for(int i = 0; i<s.size(); i++){\n            if(s[i] == \'*\' || s[i] == \'0\') continue;\n            else ans += s[i];\n        }\n\n        return ans;\n    }\n};\n```
['C++']