Minimize insertions required to make all characters of a given string equal | Function to calculate the minimum number of operations required to make all characters of the string same ; Stores count of operations ; Traverse the string ; Check if adjacent characters are same or not ; Increment count ; Prthe count obtained ; Driver Code
def minOperations ( S ) : NEW_LINE INDENT count = 0 ; NEW_LINE for i in range ( 1 , len ( S ) ) : NEW_LINE INDENT if ( S [ i ] != S [ i - 1 ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT DEDENT print ( count ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT S = "0101010101" ; NEW_LINE minOperations ( S ) ; NEW_LINE DEDENT