Python solution
Time complexity = O(26 * n)  = O(n)\nThe idea is to keep track of last index of each character and use it to check if we can pop the character on top of the sta
Time complexity = O(26 * n)  = O(n)\nThe idea is to keep track of last index of each character and use it to check if we can pop the character on top of the stack.\n```\nclass Solution(object):\n    def smallestSubsequence(self, text):\n        """\n        :type text: str\n        :rtype: str\n        """\n        last_idx = dict()\n        for i, c in enumerate(text):\n            last_idx[c] = i\n        stack = []\n        for i, c in enumerate(text):\n            if c in stack:\n                continue\n            while stack and c < stack[-1] and last_idx[stack[-1]] > i:\n                stack.pop()\n            stack.append(c)\n        return \'\'.join(stack)\n```\n\nAlso can add a set to check if character in stack,  its also O(n)\n```\nclass Solution(object):\n    def smallestSubsequence(self, text):\n        """\n        :type text: str\n        :rtype: str\n        """\n        last_idx, stack, check = dict(), [], set()\n        for i, c in enumerate(text):\n            last_idx[c] = i\n        for i, c in enumerate(text):\n            if c in check:\n                continue\n            while stack and c < stack[-1] and last_idx[stack[-1]] > i:\n                check.remove(stack[-1])\n                stack.pop()\n            check.add(c)\n            stack.append(c)\n        return \'\'.join(stack)\n```
[]