C++ ||Explained || Stack || Greedy || Easy-Understanding
\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        \n        // in string type of subsequence problem \n        \n        //stack 
```\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        \n        // in string type of subsequence problem \n        \n        //stack is always going to be a option \n        \n        //condition of popping -> curr character(s[i]) , popping character (stk.top())\n        \n        // i) popping character must be present on the right side , present right side of s[i]\n        \n        // popping character must be greater than curr character (lexicographically)\n        \n        // there may be the case that curr charceter is smaller than stk.top()\n        \n        // popping charcter , but already present in the stack \n        \n        // take care of these conditions\n        \n        vector<int> index(26 , -1);\n        \n        for(int i=0;i<s.size();i++)\n        {\n            index[s[i]-\'a\']=i;\n        }\n        \n        stack< char > stk;\n        \n        unordered_set< char > st;\n        \n        for(int i=0;i<s.size();i++)\n        {\n            while(!stk.empty() && index[stk.top()-\'a\']>i && s[i]<stk.top() && st.find(s[i])==st.end())\n            {\n                st.erase(stk.top());\n                stk.pop();\n            }\n            \n            if(st.find(s[i])==st.end())\n            {\n                stk.push(s[i]);\n                st.insert(s[i]);\n            }\n        }\n        \n        string res="";\n        \n        while(!stk.empty())\n        {\n            res.push_back(stk.top());\n            stk.pop();\n        }\n        \n        reverse(res.begin() , res.end());\n        \n        return res;\n        \n    }\n};\n```
['Stack', 'Greedy', 'C', 'C++']