Easy - Beginner Friendly || Stack || Hashmap || Monotonic Stack || Greedy || C++
Code\ncpp\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        unordered_map<char,int>last;\n        unordered_map<char,bool>taken;\n
# Code\n```cpp\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        unordered_map<char,int>last;\n        unordered_map<char,bool>taken;\n        stack<char>st;\n        string ans="";\n        for(int i=0;i<s.size();i++)\n            last[s[i]]=i;\n        for(int i=0;i<s.size();i++)\n        {\n            if(taken.find(s[i])!=taken.end())\n                continue;\n            while(st.size()!=0 && s[i]<st.top() && last[st.top()]>i)\n            {\n                taken.erase(st.top());\n                st.pop();\n            }\n            taken[s[i]]=true;\n            st.push(s[i]);\n        }\n        while(st.size()>0)\n        {\n            ans=st.top()+ans;\n            st.pop();\n        }\n        return ans;        \n    }\n};\n```
['Hash Table', 'String', 'Stack', 'Greedy', 'Monotonic Stack', 'C++']