✅✅Faster || Easy To Understand || C++ Code
Using Stack && Unordered Map\n\n Time Complexity :- O(N)\n\n Space Complexity :- O(N)\n\n\nclass Solution {\npublic:\n    string smallestSubsequence(string str)
* ***Using Stack && Unordered Map***\n\n* ***Time Complexity :- O(N)***\n\n* ***Space Complexity :- O(N)***\n\n```\nclass Solution {\npublic:\n    string smallestSubsequence(string str) {\n        \n        int n = str.size();\n        \n        // count store the frequency of element\n        \n        vector<int> count(26, 0);\n        \n        // vis keeps track of included element\n        \n        vector<bool> vis(26, false);\n        \n        // store the frequency of each element\n        \n        for(int i = 0; i < n; i++)\n        {\n            count[str[i] - \'a\']++;\n        }\n        \n        // stack will store the character in increasing order\n        \n        stack<char> st;\n        \n        for(int i = 0; i < n; i++)\n        {\n            // decrement the frequency of curr character\n            \n            count[str[i] - \'a\']--;\n            \n            // if curr character is already included\n            \n            if(vis[str[i] - \'a\'])\n            {\n                continue;\n            }\n            else\n            {\n                // remove the greater character from stack\n                \n                while(!st.empty() && str[i] < st.top() && count[st.top() - \'a\'] > 0)\n                {\n                    // mark not included\n                    \n                    vis[st.top() - \'a\'] = false;\n                    \n                    st.pop();\n                }\n                \n                // push the current character in stack\n                \n                st.push(str[i]);\n                \n                // mark included\n                \n                vis[str[i] - \'a\'] = true;\n            }\n        }\n        \n        // take out the characters from stack\n        \n        string res = "";\n        \n        while(!st.empty())\n        {\n            res = st.top() + res;\n            \n            st.pop();\n        }\n        \n        return res;\n    }\n};\n```
['Stack', 'C', 'C++']