Python | Monotonic stack, Set, and Counter
\nclass Solution:\n    def smallestSubsequence(self, s: str) -> str:\n\t\t# count how many of each character we have available in `s`\n        charCount = Count
```\nclass Solution:\n    def smallestSubsequence(self, s: str) -> str:\n\t\t# count how many of each character we have available in `s`\n        charCount = Counter(s)\n        charsInStack, charStack = set(), []\n        \n        for i, char in enumerate(s):\n\t\t\t# if char is not currently in charStack, we remove as many characters as possible and place it at the top\n            if char not in charsInStack:\n\t\t\t\t# we remove the top of the stack if there are more of that character coming up AND char is smaller lexicographically\n                while charStack and char < charStack[-1] and charCount[charStack[-1]] > 0:\n                    charsInStack.remove(charStack.pop())\n\t\t\t\t# after removing as many characters as possible, we add char to the top of the stack\n                charStack.append(char)\n\t\t\t\t# we use a set to keep track of what characters are in the stack to lookup in O(1) time\n                charsInStack.add(char)\n            charCount[char] -= 1\n\t\t\n\t\t# the resulting stack has every character from `s` exacyly once and in the best lexicographical position possible\n        return "".join(charStack)\n```
['Monotonic Stack', 'Ordered Set', 'Python']