Minimum number of characters to be removed to make a binary string alternate | Returns count of minimum characters to be removed to make s alternate . ; if two alternating characters of string are same ; result += 1 then need to delete a character ; Driver code
def countToMake0lternate ( s ) : NEW_LINE INDENT result = 0 NEW_LINE for i in range ( len ( s ) - 1 ) : NEW_LINE INDENT if ( s [ i ] == s [ i + 1 ] ) : NEW_LINE DEDENT return result NEW_LINE DEDENT if __name__ == " _ _ main _ _ " : NEW_LINE INDENT print ( countToMake0lternate ( "000111" ) ) NEW_LINE print ( countToMake0lternate ( "11111" ) ) NEW_LINE print ( countToMake0lternate ( "01010101" ) ) NEW_LINE DEDENT