C++ EASY AND CLEAN SOLUTION USING STACK
Code\n\nclass Solution {\npublic:\n    string smallestSubsequence(string text) {\n        vector<int> freq(26,0);\n        vector<int> vis(26,0);\n        stack
# Code\n```\nclass Solution {\npublic:\n    string smallestSubsequence(string text) {\n        vector<int> freq(26,0);\n        vector<int> vis(26,0);\n        stack<char> st;\n        for(auto it:text) freq[it-\'a\']++;\n        for(int i=0;i<text.size();i++){\n            char c=text[i];\n            freq[c-\'a\']--;\n            if(vis[c-\'a\']) continue;\n            while(!st.empty() && st.top()>c && freq[st.top()-\'a\']>0){\n                vis[st.top()-\'a\']--;\n                st.pop();\n            }\n            vis[c-\'a\']++;\n            st.push(c);\n        }\n        string str="";\n        while(!st.empty()){\n            str=str+st.top();\n            st.pop();\n        }\n        reverse(str.begin(),str.end());\n        return str;\n    }\n};\n```
['C++']