C++ || Monotonic Stack || Easy Solution
\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity: O(n)\n\n# Code\n\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n       
\n\n# Complexity\n- Time complexity:O(n)\n\n- Space complexity: O(n)\n\n# Code\n```\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        vector<int> vis(26,0);\n        unordered_map<char,int> mp;\n        for(auto ch : s) mp[ch]++;\n        string ans="";\n        for(int i=0;i<s.size();i++){\n            mp[s[i]]--;\n            if(vis[s[i]-\'a\']) continue;\n            else{\n                while(!ans.empty() && ans.back()>s[i] && mp[ans.back()]){\n                    vis[ans.back()-\'a\']=0;\n                    ans.pop_back();\n                }\n                ans.push_back(s[i]);\n                vis[s[i]-\'a\']=1;\n            }\n        }\n        return ans;\n    }\n};\n```
['String', 'Monotonic Stack', 'C++']