human
Lexicographically smallest string formed by appending a character from the first K characters of a given string | Function to find the new string thus formed by removing characters.
new string.
Remove characters until the string is empty.
Traverse to find the smallest character in the first k characters.
append the smallest character.
removing the lexicographically smallest character from the string.
Driver Code"
Solution in Python:
assistant
#Here is code to lexicographically smallest string formed by appending a character from the first K characters of a given string and the other steps required.
 def newString ( s , k ) :
	X = " "
	while ( len ( s ) > 0 ) :
		temp = s [ 0 ]
		i = 1
		while ( i < k and i < len ( s ) ) :
			if ( s [ i ] < temp ) :
				temp = s [ i ]
			i += 1
		X = X + temp
		for i in range ( k ) :
			if ( s [ i ] == temp ) :
				s = s [ 0 : i ] + s [ i + 1 : ]
				break
	return X
if __name__ == ' _ _ main _ _ ' :
	s = " gaurang "
	k = 3
	print ( newString ( s , k ) )