CPP | EASY | 100% BEATS TIME AND MEM | SMALL
\nstring smallestSubsequence(string text) {\n\tstack<char> st;\n\tvector<int> last(256, 0), seen(256, 0);\n\tfor(int i = 0; i < text.size(); i++)\n\t\tlast[text
```\nstring smallestSubsequence(string text) {\n\tstack<char> st;\n\tvector<int> last(256, 0), seen(256, 0);\n\tfor(int i = 0; i < text.size(); i++)\n\t\tlast[text[i]] = i;\n\tfor(int i = 0; i < text.size(); i++){\n\t\tif(seen[text[i]])\n\t\t\tcontinue;\n\n\t\twhile(st.size() and st.top() > text[i] and last[st.top()] > i)\n\t\t\tseen[st.top()] = 0, st.pop(); \n\n\t\tst.push(text[i]), seen[text[i]] = 1;\n\t}\n\tstring res = "";\n\twhile(st.size())\n\t\tres += st.top(), st.pop();\n\treverse(res.begin(), res.end());\n\treturn res;\n}\n```
['Array', 'Stack', 'Greedy', 'C', 'C++']