Segregate 1 s and 0 s in separate halves of a Binary String | Function to count the minimum number of operations required to segregate all 1 s and 0 s in a binary string ; Stores the count of unequal pair of adjacent characters ; If an unequal pair of adjacent characters occurs ; For odd count ; For even count ; Given string ; Length of the string ; Prints the minimum count of operations required
def minOps ( s , N ) : NEW_LINE INDENT ans = 0 NEW_LINE for i in range ( 1 , N ) : NEW_LINE INDENT if ( s [ i ] != s [ i - 1 ] ) : NEW_LINE INDENT ans += 1 NEW_LINE DEDENT DEDENT if ( ans % 2 == 1 ) : NEW_LINE INDENT print ( ( ans - 1 ) // 2 ) NEW_LINE return NEW_LINE DEDENT print ( ans // 2 ) NEW_LINE DEDENT str = "01011100" NEW_LINE N = len ( str ) NEW_LINE minOps ( str , N ) NEW_LINE