Minimum subarray reversals required to make given binary array alternating | Function to count minimum subarray reversal operations required to make array alternating ; Stores minimum count of operations required to make array alternating ; Traverse the array ; If arr [ i ] is greater than arr [ i + 1 ] ; Update cntOp ; Driver Code
def minimumcntOperationReq ( arr , N ) : NEW_LINE INDENT cntOp = 0 NEW_LINE for i in range ( N - 1 ) : NEW_LINE INDENT if ( arr [ i ] == arr [ i + 1 ] ) : NEW_LINE INDENT cntOp += 1 NEW_LINE DEDENT DEDENT return ( cntOp + 1 ) // 2 NEW_LINE DEDENT arr = [ 1 , 1 , 1 , 0 , 1 , 0 , 0 , 0 ] NEW_LINE N = len ( arr ) NEW_LINE print ( minimumcntOperationReq ( arr , N ) ) NEW_LINE