Easy C++ solution using Stack
```\nstring smallestSubsequence(string str) {\n        int lastIndex[26] = {0};\n        bool charUsed[26] = {false};\n        \n        stack s;\n        \n   
```\nstring smallestSubsequence(string str) {\n        int lastIndex[26] = {0};\n        bool charUsed[26] = {false};\n        \n        stack<char> s;\n        \n        for(int i=0;i<str.size();i++){\n            lastIndex[str[i]-\'a\'] = i;\n        }\n        \n        for(int i=0;i<str.size();i++){\n            char ch = str[i];\n            if(!charUsed[ch-\'a\']){\n                while(!s.empty() && s.top()>ch && lastIndex[s.top()-\'a\'] > i){\n                    charUsed[s.top()-\'a\'] = false;\n                    s.pop();\n                }\n                s.push(ch);\n                charUsed[ch-\'a\'] = true;\n            }\n        }\n        \n        string ans;\n        while(!s.empty()){\n            ans += s.top();\n            s.pop();\n        }\n        \n        string finalans;\n        finalans = ans;\n        reverse(finalans.begin(),finalans.end());\n        \n        return finalans;\n    }
[]