[Python3] stack O(N)
Algo\nScan through s via a stack. If the current character is not in stack, we pop out characters in stack from the top that are larger than the current one and
**Algo**\nScan through `s` via a `stack`. If the current character is not in stack, we pop out characters in stack from the top that are larger than the current one and are still available later in `s`. \n\n**Implementation**\n```\nclass Solution:\n    def smallestSubsequence(self, s: str) -> str:\n        loc = {x: i for i, x in enumerate(s)}\n        stack = []\n        for i, x in enumerate(s): \n            if x not in stack: \n                while stack and x < stack[-1] and i < loc[stack[-1]]: stack.pop()\n                stack.append(x)\n        return "".join(stack)\n```\n\n**Analysis**\nTime complexity `O(N)`\nSpace complexity `O(N)`
['Python3']