human
Minimum flips required to generate continuous substrings of 0 â €™ s and 1 â €™ s | Python3 implementation of the above approach.
Traverse input string and store the count of 0.
Traverse the input string again to find minimum number of flips.
Driver code"
How can the above be solved in Python?
 Give me a code to minimum flips required to generate continuous substrings of 0 â €™ s and 1 â €™ s and the other steps required?
assistant
#Here is code to minimum flips required to generate continuous substrings of 0 â €™ s and 1 â €™ s and the other steps required.
 def minChanges ( str , N ) :
	count0 = 0
	count1 = 0
	for x in str :
		count0 += ( x == '0' )
	res = count0
	for x in str :
		count0 -= ( x == '0' )
		count1 += ( x == '1' )
		res = min ( res , count1 + count0 )
	return res
N = 9
str = "000101001"
print ( minChanges ( str , N ) )