human
Lexicographically largest possible String after removal of K characters | Python3 program to implement the above approach.
Final result string.
If the current char exceeds the character at the top of the stack.
Remove from the end of the string.
Decrease k for the removal.
Insert current character.
Perform remaining K deletions from the end of the string.
Return the string.
Driver code"
How can the above be solved in Python?
assistant
#Here is code to lexicographically largest possible String after removal of K characters and the other steps required.
 def largestString ( num , k ) :
	ans = [ ]
	for i in range ( len ( num ) ) :
		while ( len ( ans ) and ans [ - 1 ] < num [ i ] and k > 0 ) :
			ans . pop ( )
			k -= 1
		ans . append ( num [ i ] )
	while ( len ( ans ) and k ) :
		k -= 1
		ans . pop ( )
	return ans
str = " zyxedcba "
k = 1
print ( * largestString ( str , k ) , sep = " " )