Without Stack
\n\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        unordered_map<char, int> map;\n        for (int i = 0; i < s.size(); i++)\n  
\n```\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        unordered_map<char, int> map;\n        for (int i = 0; i < s.size(); i++)\n            map[s[i]]++;\n        string ans = "";\n        vector<bool> visited(26, false);\n        for (int i = 0; i < s.size(); i++)\n        {\n            if (visited[s[i] - \'a\'])\n                map[s[i]]--;\n            while (ans.size() > 0 && visited[s[i] - \'a\'] == false && ans.back() >= s[i] && map[ans.back()] > 1)\n            {\n                visited[ans.back() - \'a\'] = false;\n                map[ans.back()]--;\n                ans.pop_back();\n            }\n            if (!visited[s[i] - \'a\'])\n            {\n                ans.push_back(s[i]);\n                visited[s[i] - \'a\'] = true;\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'C++']