human
Can you provide a code to find Binary string by converting all 01 or 10 to 11 after M iterations and the other steps required given the following:
Find Binary string by converting all 01 or 10 to 11 after M iterations | Function to find the modified binary string after M iterations.
Set the value of M to the minimum of N or M ..
Declaration of current string state.
Loop over M iterations.
Set the current state as null before each iteration.
Check if this zero has exactly one 1 as neighbour.
Flip the zero.
If there is no change , then no need for further iterations ..
Set the current state as the new previous state.
Driver Code.
Given String.
Number of Iterations.
Function Call"
Solution in Python:
assistant
#Here is code to find Binary string by converting all 01 or 10 to 11 after M iterations and the other steps required.
 def findString ( str , M ) :
	N = len ( str )
	M = min ( M , N )
	s1 = " "
	while ( M != 0 ) :
		s1 = " "
		for i in range ( N - 1 ) :
			if ( str [ i ] == '0' ) :
				if ( ( str [ i - 1 ] == '1' and str [ i + 1 ] != '1' ) or ( str [ i - 1 ] != '1' and str [ i + 1 ] == '1' ) ) :
					s1 += '1'
				else :
					s1 += '0'
			else :
				s1 += '1'
		if ( str == s1 ) :
			break
		s1 += '1'
		str = s1
		M -= 1
	print ( s1 )
if __name__ == ' _ _ main _ _ ' :
	str = "0110100"
	M = 3
	findString ( str , M )