python stack
python\nclass Solution:\n    \'\'\'\n    Time complexity : O(n)\n    Space complexity : O(n)\n    \'\'\'\n    def smallestSubsequence(self, text: str) -> str:\n
```python\nclass Solution:\n    \'\'\'\n    Time complexity : O(n)\n    Space complexity : O(n)\n    \'\'\'\n    def smallestSubsequence(self, text: str) -> str:\n        count = collections.Counter(text)\n        visited, stack = set(), []\n        \n        for ch in text:\n            count[ch] -= 1\n            if ch not in visited:\n                # if stack[-1] > ch and stack[-1] will comes in later, we can remove it\n                while stack and stack[-1] > ch and count[stack[-1]] > 0:\n                    visited.remove(stack.pop())\n                stack.append(ch)\n                visited.add(ch)\n        \n        return \'\'.join(stack)\n\n```
['Stack', 'Python3']