human
Check if count of 1 s can be made greater in a Binary string by changing 0 s adjacent to 1 s | Function to check whether in a given binary string can we make number of 1 ' s ▁ greater ▁ than ▁ the ▁ number ▁ of ▁ 0' s by doing the given operation.
Stores the count of 0 's.
Stores the count of 1 's.
Traverse through the string S.
Check current character is 1.
Update cnt1.
Update cnt0.
Traverse through the string S.
Check curretn character is 1.
Check if left adjacent character is 0.
Change the left adjacent character to _.
Update the cnt0.
Check if right adjacent character is 0.
Change the right adjacent character to _.
Update the cnt0.
Check count of 1 ' s ▁ is ▁ greater ▁ ▁ than ▁ the ▁ count ▁ of ▁ 0' s.
Driver Code"
How can the above be solved in Python?
assistant
#Here is code to check if count of 1 s can be made greater in a Binary string by changing 0 s adjacent to 1 s and the other steps required.
 def isOnesGreater ( S , N ) :
	S = list ( S )
	cnt0 = 0
	cnt1 = 0
	for i in range ( N ) :
		if ( S [ i ] == '1' ) :
			cnt1 += 1
		else :
			cnt0 += 1
	for i in range ( N ) :
		if ( S [ i ] == '1' ) :
			if ( i > 0 and S [ i - 1 ] == '0' ) :
				S [ i - 1 ] = ' _ '
				cnt0 -= 1
			elif ( i < N and S [ i + 1 ] == '0' ) :
				S [ i + 1 ] = ' _ '
				cnt0 -= 1
	if ( cnt1 > cnt0 ) :
		print ( " Yes " )
	else :
		print ( " No " )
S = "01"
N = len ( S )
isOnesGreater ( S , N )