Having Memory Limit Exceeded ! Can anyone help?
Can somebody explain why my 2nd Approach (Used unordered_map>)didn\'t work but 1st Approach (vector>) worked.\n+ I agree :\nThat the 1st approach is a bit optim
Can somebody explain why my 2nd Approach (Used unordered_map<int,vector<int>>)didn\'t work but 1st Approach (vector<vector<int>>) worked.\n+ I agree :\nThat the 1st approach is a bit optimised but that should effec T.C. right?\nBut my 2nd approach is having Memory Limit exceeded! How ??\n\n## Approach 1\n### (vector<vector<int>>mp(26,vector<int>())) [Accepted]\n```\nclass Solution {\npublic:\n    string clearStars(string s) {\n        int n=s.size();\n        vector<vector<int>>mp(26,vector<int>());\n        for(int i=0;i<n;i++)\n        {\n            if(s[i]!=\'*\')\n            {\n                mp[s[i]-\'a\'].push_back(i);\n            }\n            else if(s[i]==\'*\')\n            {\n                for(int j=0;j<26;j++)\n                {\n                    if(mp[j].size()>0)\n                    {\n                        int idx=mp[j][mp[j].size()-1];\n                        s[idx]=\'*\';\n                        mp[j].pop_back();\n                        break;\n                    }\n                }\n            }\n        }\n        string ans="";\n        for(int i=0;i<n;i++)\n        {\n            if(s[i]!=\'*\')\n            {\n                ans+=s[i];\n            }\n        }\n        return ans;\n    }\n};\n```\n## Approach 2 \n### (unordered_map<char,vector<int>>mp)[Memory Limit Exceeded]\n```\nclass Solution {\npublic:\n    string clearStars(string s) {\n        int n=s.size();\n        unordered_map<char,vector<int>>mp;\n        for(int i=0;i<n;i++)\n        {\n            if(s[i]!=\'*\')\n            {\n                mp[s[i]].push_back(i);\n            }\n            else\n            {\n                char smallest=\'z\';\n                for(auto it:mp)\n                {\n                   if(it.first<smallest && it.second.size()>0)\n                   {\n                     smallest=it.first;\n                   }\n                }\n                int idx=mp[smallest][mp[smallest].size()-1];\n                s[idx]=\'*\';\n                mp[smallest].pop_back();\n            }\n        }\n        string ans="";\n        for(int i=0;i<n;i++)\n        {\n            if(s[i]!=\'*\')\n            {\n                ans+=s[i];\n            }\n        }\n        return ans;\n    }\n};\n```\nPlease help!\nThank You.
['C']