Minimum flips of odd indexed elements from odd length subarrays to make two given arrays equal | Function to find the minimum flip of subarrays required at alternate index to make binary arrays equals ; Stores count of total operations ; Stores count of consecutive unequal elements ; Loop to run on odd positions ; Incrementing the global counter ; Change count to 0 ; If all last elements are equal ; Loop to run on even positions ; Incrementing the global counter ; Change count to 0 ; Print minimum operations ; Driver Code ; Function Call
def minOperation ( X , Y , n ) : NEW_LINE INDENT C = 0 ; NEW_LINE count = 0 ; NEW_LINE for i in range ( 1 , n , 2 ) : NEW_LINE INDENT if ( X [ i ] != Y [ i ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( count != 0 ) : NEW_LINE INDENT C += 1 ; NEW_LINE DEDENT count = 0 ; NEW_LINE DEDENT DEDENT if ( count != 0 ) : NEW_LINE INDENT C += 1 ; NEW_LINE DEDENT count = 0 ; NEW_LINE for i in range ( 0 , n , 2 ) : NEW_LINE INDENT if ( X [ i ] != Y [ i ] ) : NEW_LINE INDENT count += 1 ; NEW_LINE DEDENT else : NEW_LINE INDENT if ( count != 0 ) : NEW_LINE INDENT C += 1 ; NEW_LINE DEDENT count = 0 ; NEW_LINE DEDENT DEDENT if ( count != 0 ) : NEW_LINE INDENT C += 1 ; NEW_LINE DEDENT print ( C ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT X = [ 1 , 0 , 0 , 0 , 0 , 1 ] ; NEW_LINE Y = [ 1 , 1 , 0 , 1 , 1 , 1 ] ; NEW_LINE N = len ( X ) ; NEW_LINE minOperation ( X , Y , N ) ; NEW_LINE DEDENT