Check if all bits can be made same by flipping two consecutive bits | Function to check if Binary string can be made equal ; Counting occurence of zero and one in binary string ; From above observation ; Driver code
def canMake ( s ) : NEW_LINE INDENT o = 0 ; z = 0 ; NEW_LINE for i in range ( len ( s ) ) : NEW_LINE INDENT if ( ord ( s [ i ] ) - ord ( '0' ) == 1 ) : NEW_LINE INDENT o += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT z += 1 ; NEW_LINE DEDENT DEDENT if ( o % 2 == 1 and z % 2 == 1 ) : NEW_LINE INDENT return " NO " ; NEW_LINE DEDENT else : NEW_LINE INDENT return " YES " ; NEW_LINE DEDENT DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT s = "01011" ; NEW_LINE print ( canMake ( s ) ) ; NEW_LINE DEDENT