human
Minimum number of replacements to make the binary string alternating | Set 2 | Function to return the minimum number of characters of the given binary string to be replaced to make the string alternating.
If there is 1 at even index positions.
If there is 0 at odd index positions.
Driver code"
Solution in Python:
assistant
#Here is code to minimum number of replacements to make the binary string alternating and the other steps required.
 def minReplacement ( s , length ) :
	ans = 0
	for i in range ( 0 , length ) :
		if i % 2 == 0 and s [ i ] == '1' :
			ans += 1
		if i % 2 == 1 and s [ i ] == '0' :
			ans += 1
	return min ( ans , length - ans )
if __name__ == " _ _ main _ _ " :
	s = "1100"
	length = len ( s )
	print ( minReplacement ( s , length ) )