[c++][Runtime: 0 ms, faster than 100.00%][easy understanding]
\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        stack<char> st;\n\t\t//visited will contain if s[i] is present in current resul
```\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        stack<char> st;\n\t\t//visited will contain if s[i] is present in current result Stack\n        vector<int> visited(26,0),cnt(26,0);\n        for(int i=0;i<s.size();i++) cnt[s[i]-\'a\']++;  //count the number of occurences of s[i]\n        for(int i=0;i<s.size();i++){\n            cnt[s[i]-\'a\']--;  //decrement number of characters remaining in the string\n            if(visited[s[i]-\'a\']) continue;  //if character is already present in stack, dont bother\n\t\t\t//if current character is smaller than last character in stack which occurs later in the string again\n        //it can be removed and  added later e.g stack = bc remaining string abc then a can pop b and then c\n            while(!st.empty() && s[i]<st.top() && cnt[st.top()-\'a\']!=0){\n                visited[st.top()-\'a\']=0;\n                st.pop();\n            }\n            st.push(s[i]); //add current character and mark it as visited\n            visited[s[i]-\'a\']=1;\n        }\n        s.clear();\n        while(!st.empty()){\n            s=st.top()+s;\n            st.pop();\n        }\n        return s;\n    }\n};\n```\n**Feel free to ask any question in the comment section.**\nI hope that you\'ve found the solution useful.\nIn that case, **please do upvote and encourage me** to on my quest to document all leetcode problems\uD83D\uDE03\nHappy Coding :)\n
['Stack', 'C']