Smallest Subsequence of Distinct Characters (easiest explanation)
\nstring smallestSubsequence(string s) {\n//         we will take the stack which will store the elements so that we can delete the \n//         useless element
```\nstring smallestSubsequence(string s) {\n//         we will take the stack which will store the elements so that we can delete the \n//         useless elements.\n        stack<char> st;\n//         now we will make a map which will store the frequency of each element\n        unordered_map<char, int> freq;\n        for(auto it : s){\n            freq[it]++;\n        }\n//         Now we will make a map which will tell use wheter we used the current element or not\n        unordered_map<char, bool>check;\n        for(int i = 0 ; i< s.length(); i++){\n            check[s[i]] = false;    \n        }\n//      there will be different cases now ;\n        for(int i = 0 ; i< s.size(); i++){\n//             we will decrease the freq each time when we face partivular element \n            freq[s[i]]--;\n//             if the element is used then we will skip that \n            if(check[s[i]])continue;\n            else{\n                \n            \n//          if st.top() is greater than the current element then we will remove the previous \n//             elemtent if the frequency of that elemtent is greater than zero i.e the top \n//             elemtent is present somewhere  after the current element .\n            while( st.size() and st.top() > s[i] and freq[st.top()]){\n//                 the elements which i removed i will make there check as false as those are\n//                 present somewhere after the current element i.e they will be checked in \n//                 future\n                check[st.top()]= false;\n                st.pop();\n                \n            }\n//             we will add each element into the stack\n                st.push(s[i]);\n                check[s[i]]= true;\n            }\n            \n        }\n//         now store the result into a string \n          string res = "";\n        \n        while(!st.empty())\n        {\n            res.push_back(st.top());\n            \n            st.pop();\n        }\n//         as stack is storing the elements so reverse the result\n        reverse(res.begin(), res.end());\n        \n        return res;\n    }\n```
[]