C++ faster than 100%, Map based
Map based approach:\nThings to remember while adding or removing a character in the final string (fi)\nAdd the character if it is not present in the string till
Map based approach:\nThings to remember while adding or removing a character in the final string (fi)\nAdd the character if it is not present in the string till now.\nRemove if:\n1. Their are more occurances of the same character ahead (Check using map)\n2. Next character in string s (s[i]) is greater than the last character in final string.\n3. s[i] is not present in the final string already.\n\n\n    string removeDuplicateLetters(string s) {\n        string fi;\n        unordered_map<char, int> m;\n        \n        for(int i=0;i<s.length();i++)\n            m[s[i]]++;\n        \n        if(fi.length()==m.size())\n            return fi;\n        \n        for(int i=0;i<s.length();i++){\n            \n            while(fi.length()>0 && fi.back()>s[i] && m[fi.back()]>0 && fi.find(s[i])==-1)\n                fi.pop_back();\n                \n            \n            if(fi.find(s[i])==-1)\n                fi.push_back(s[i]);\n            \n            m[s[i]]--;\n        }    \n        return fi;\n    }\n
[]