C++ 0ms O(n) using string as stack
\nstring smallestSubsequence(string text) {\n        if(text.length()==0)\n            return text;\n        vector<int> freq(26,0);\n        for(char &ch : tex
```    \nstring smallestSubsequence(string text) {\n        if(text.length()==0)\n            return text;\n        vector<int> freq(26,0);\n        for(char &ch : text)\n            freq[ch-\'a\']++;\n        \n        vector<bool> seen(26,0);\n        string ans="0";\n        for(char &ch: text)\n        {\n            freq[ch-\'a\']--;\n            if(seen[ch-\'a\']==true)  //we can not have duplicate char\n                continue;\n            while(ans.back() > ch && freq[ans.back()-\'a\'] >0)  //We\'ll only pop when ans.back() char has freq >0 (means it cannot occur later in string so must preserve it because we have to have each letter in ans and distinct also)\n            {\n                seen[ans.back()-\'a\']=false;  //as we\'are removing the last char so we mark it not vis in ans string\n                ans.pop_back();\n            }\n                   \n            seen[ch-\'a\']=true;\n            ans+=ch;\n        }\n        return ans.substr(1);\n    }\n\n```
['C']