C++ double 100% greedy with explanations
we first count the occurance of each letter\n2. loop throught the given string again\n\ta. if current char if less than the back of our current result, and ther
1. we first count the occurance of each letter\n2. loop throught the given string again\n\ta. if current char if less than the back of our current result, and there are more same letter as current back, we pop the back of current result.\n3. use another vector to remember if any letter has been used already, so we use each letter only once.\n```\nclass Solution {\npublic:\n    string smallestSubsequence(string text) {\n        vector<int> count(26, 0);\n        for (char c : text) {\n            count[c - \'a\'] += 1;\n        }\n        \n        string result = "";\n        vector<bool> used(26, false);\n        for (char c : text) {\n            if (used[c - \'a\']) {\n                count[c - \'a\'] -= 1;\n                continue;\n            }\n            while (!result.empty() and c < result.back() and count[result.back() - \'a\'] > 0) {\n                used[result.back() - \'a\'] = false;\n                result.pop_back();\n            }\n            result.push_back(c);\n            used[c - \'a\'] = true;\n            count[c - \'a\'] -= 1;\n        }\n        return result;\n    }\n};\n```
[]