C++ solution using stack
Dry Run\nINPUT - "cbacdcbc"\n\n\ni = 0\nans = \'c\'\nExplaination - Since c not considered\n\n\n\ni = 1\nans = \'b\'\nExplaination - Since c is present afterwar
Dry Run\nINPUT - "cbacdcbc"\n\n```\ni = 0\nans = \'c\'\nExplaination - Since c not considered\n```\n\n```\ni = 1\nans = \'b\'\nExplaination - Since c is present afterwards, we can remove the c added before\n```\n\n```\ni = 2\nans = \'a\'\nExplaination - Since b is present afterwards, we can remove the b added before\n```\n\n```\ni = 3\nans = \'ac\'\nExplaination - Since c not considered till now. Note previously considered c has been remove. Same has to be reflected in the bool array.\n```\n\n```\ni = 4\nans = \'acd\'\nExplaination - Since d not considered till now\n```\n\n```\ni = 5\nans = \'acd\'\nExplaination - c already considered\n```\n\n```\ni = 6\nans = \'acdb\'\nExplaination - Eventhough d is greater than b, it is not removed as d doesn\'t appear afterwards. Add b at the end.\n```\n\n```\ni = 7\nans = \'acdb\'\nExplaination - c already considered.\n```\n\nFINAL ANSWER - \'acdb\'\n\nCODE - \n\n```\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n        \n        // store array of last index in s\n        vector<int> lastIdx (26, 0);\n        for(int i = 0 ; i < s.size() ; i++)\n            lastIdx[int(s[i])- int(\'a\')]  = i;\n        \n        // bool array to store if the char has been considered\n        vector<bool> isAdded (26, false);\n        \n        stack<char> k;\n        for(int i = 0; i < s.size() ; i++){\n            // if char already present then continue\n            if (isAdded[int(s[i]) - int(\'a\')])\n                continue;\n            \n            // if char to be added is smaller than top of \n            // stack and the char at top of stack is present\n            // later, then pop.\n            // continue till possible\n            while(!k.empty() && k.top() > s[i] && i  < lastIdx[int(k.top()) - int(\'a\')]){\n                isAdded[int(k.top()) - int(\'a\')] = false;\n                k.pop();\n            }\n            \n            // add to stack and mark as added\n            isAdded[int(s[i])-int(\'a\')] = true;\n            k.push(s[i]);\n            \n        }\n        \n        // traverse through stack and create ans\n        string ans = "";\n        while(!k.empty()){\n            ans = k.top() + ans;\n            k.pop();\n        }\n        return ans;\n    }\n};\n```
['Stack', 'C']