beats 100% user with cpp
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    string smallestSubsequence(string s) {\n    int n = s.size();\n    string ans = "";\n    vector<bool> taken(27 , false);\n    vector<int> lastOcc(27 , 0);\n    for(int i = 0 ; i< n ; i++){\n        lastOcc[s[i] - \'a\'] = i ; \n    }\n    for(int i = 0 ; i< n ; i++){\n        if(taken[s[i] - \'a\']) continue;\n        if(ans.size()== 0 || ans.back() <s[i]){\n            ans+= s[i];\n            taken[s[i] - \'a\'] = true;\n        }\n        else{\n            while(ans.size()>0 && ans.back()>s[i] && lastOcc[ans.back()-\'a\'] > i){\n             \n                taken[ans.back()-\'a\'] = false;\n                   ans.pop_back() ;\n            }\n          ans+= s[i];\n          taken[s[i] - \'a\'] = true;\n        }\n    }\n    return ans;\n    // map<char,int> mp;\n    // for(auto t: s){\n    //     mp[t]++;\n    // }\n    // string ans = "";\n    // int fr =0 ;\n    // for(int i = 0 ; i< n; i++){\n    //     if(mp[s[i]] == 0) continue;\n    //     if(mp[s[i]] ==1){\n    //         mp[s[i]]--;\n    //         cout<<s[i]<<endl;\n    //         ans += s[i];\n    //     }else{\n    //         int j = i+1 ; \n    //         map<char,int> dp = mp;\n    //         int cnt = i ; \n    //         char c = s[i];\n    //         dp[s[j]]--;\n    //         while(dp[s[j]] !=1  && j<n){\n    //             cout<<j<<" "<<dp[s[j]]<<" "<<s[j]<<endl;\n    //             if(s[j]<c && dp[s[j]]  >1 )\n    //             {\n    //                 cnt = j ; \n    //                 c = s[j];\n    //             }\n    //             dp[s[j]]--;\n    //             j++;\n    //         }\n    //         if(j<n){\n    //             if(c>s[j]){\n    //                 cout<<s[j]<<" "<<j<<endl;\n    //                 cnt = j ; \n    //                 c = s[j];\n    //             }\n    //         }\n    //         while(i<cnt ){\n    //             mp[s[i]]--;\n    //             i++;\n    //         }\n    //         ans+=c;\n    //         mp[c] = 0 ;\n    //       cout<<i<<" "<<c<<endl;\n    //       cout<<fr<<endl;\n    //       fr++;\n    //     }\n    // }\n    // return ans;\n    }\n};\n```
['C++']