human
Convert given Binary string S to all 1 s by changing all 0 s to 1 s in range [ i + 1 , i + K ] if S [ i ] is 1 | Function to check whether all 0 s in the string can be changed into 1 s.
Store the count of 0 s converted for the last occurrence of 1.
Declere a stack.
Traverse the string , S.
If stack is empty.
There is no 1 that can change this 0 to 1.
Push 1 into the stack.
The last 1 has reached its limit.
New 1 has been found which can now change at most K 0 s.
If flag is 1 , pr " YES " else pr " NO ".
Driver code.
Given Input.
Function call"
How can the above be solved in Python?
 Give me a code to convert given Binary string S to all 1 s by changing all 0 s to 1 s in range [ i + 1 , i + K ] if S [ i ] is 1 and the other steps required?
assistant
#Here is code to convert given Binary string S to all 1 s by changing all 0 s to 1 s in range [ i + 1 , i + K ] if S [ i ] is 1 and the other steps required.
 def changeCharacters ( S , N , K ) :
	flag = 1
	count = 0
	st = [ ]
	for i in range ( N ) :
		if len ( st ) == 0 :
			if ( S [ i ] == '0' ) :
				flag = 0
				break
			count = 0
			st . append ( S [ i ] )
		else :
			if ( S [ i ] == '0' ) :
				count += 1
				if ( count == K ) :
					del st [ - 1 ]
					count = 0
			else :
				count = 0
	if ( flag ) :
		print ( " YES " )
	else :
		print ( " NO " )
if __name__ == ' _ _ main _ _ ' :
	S = "100100"
	N = len ( S )
	K = 2
	changeCharacters ( S , N , K )