class Solution(object):
def smallestSubsequence(self, s):
"""
:type s: str
:rtype: str
"""
stack = []
data = set()
for i,c in enumerate(s):
if c not in data:
while stack and stack[-1]>c and stack[-1] in s[i:]:
data.remove(stack.pop())
stack.append(c)
data.add(c)
return "".join(stack)