Python Easy Monotonic Stack
Intuition\ncheckout https://leetcode.com/problems/remove-duplicate-letters/solutions/2666355/python-easy-stack-o-n/\n Describe your first thoughts on how to sol
# Intuition\ncheckout https://leetcode.com/problems/remove-duplicate-letters/solutions/2666355/python-easy-stack-o-n/\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```\nclass Solution:\n    def smallestSubsequence(self, s: str) -> str:\n        count = Counter(s)\n        stack = deque()\n        result = set()\n        for i in s:\n            if i in result: \n                count[i] -= 1\n                continue\n\n            while(stack and stack[-1] > i and count[stack[-1]] > 1):\n                count[stack[-1]] -= 1\n                result.remove(stack[-1])\n                stack.pop()\n\n            stack.append(i)\n            result.add(i)\n\n        return "".join(stack)\n```
['Stack', 'Monotonic Stack', 'Python3']