human
Lexicographically smallest string formed by removing duplicates | Function that finds lexicographically smallest after removing the duplicates from the given string.
Stores the frequency of characters.
Mark visited characters.
Stores count of each character.
Stores the resultant string.
Decrease the count of current character.
If character is not already in answer.
Last character > S [ i ] and its count > 0.
Mark letter unvisited.
Add s [ i ] in res and mark it visited.
Return the resultant string.
Driver Code.
Given S.
Function Call"
How can the above be solved in Python?

Can you provide a code to lexicographically smallest string formed by removing duplicates and the other steps required?
assistant
#Here is code to lexicographically smallest string formed by removing duplicates and the other steps required.
 def removeDuplicateLetters ( s ) :
	cnt = [ 0 ] * 26
	vis = [ 0 ] * 26
	n = len ( s )
	for i in s :
		cnt [ ord ( i ) - ord ( ' a ' ) ] += 1
	res = [ ]
	for i in range ( n ) :
		cnt [ ord ( s [ i ] ) - ord ( ' a ' ) ] -= 1
		if ( not vis [ ord ( s [ i ] ) - ord ( ' a ' ) ] ) :
			while ( len ( res ) > 0 and res [ - 1 ] > s [ i ] and cnt [ ord ( res [ - 1 ] ) - ord ( ' a ' ) ] > 0 ) :
				vis [ ord ( res [ - 1 ] ) - ord ( ' a ' ) ] = 0
				del res [ - 1 ]
			res += s [ i ]
			vis [ ord ( s [ i ] ) - ord ( ' a ' ) ] = 1
	return " " . join ( res )
if __name__ == ' _ _ main _ _ ' :
	S = " acbc "
	print ( removeDuplicateLetters ( S ) )