Check if an array can be converted to another given array by swapping pairs of unequal elements | Function to check if arr1 [ ] can be converted to arr2 [ ] by swapping pair ( i , j ) such that i < j and arr [ i ] is 1 and arr [ j ] is 0 ; Stores the differences of prefix sum of arr1 and arr2 ; Stores the count of 1 and zero of arr1 ; Stores the count of 1 and zero of arr2 ; Iterate in the range [ 0 , N - 1 ] ; If arr1 [ i ] is 1 , then increment arr1_one by one ; Otherwise increment arr1_zero by one ; If arr2 [ i ] is 1 , then increment arr2_one by one ; Otherwise increment arr2_zero by one ; Check if number of 1 s and 0 s of arr1 is equal to number of 1 s and 0 s of arr2 respectievly ; Iterate over the range [ 0 , N - 1 ] ; Increment count by differences arr1 [ i ] and arr2 [ i ] ; Check if number of 1 's in  arr2 are more than arr1 and  then print "No" ; Finally , print " Yes " ; Driver Code ; Given input a ; Size of the array ; Function Call
def canMakeEqual ( arr1 , arr2 , N ) : NEW_LINE INDENT count = 0 NEW_LINE arr1_one = 0 NEW_LINE arr1_zero = 0 NEW_LINE arr2_one = 0 NEW_LINE arr2_zero = 0 NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr1 [ i ] == 1 ) : NEW_LINE INDENT arr1_one += 1 NEW_LINE DEDENT elif ( arr1 [ i ] == 0 ) : NEW_LINE INDENT arr1_zero += 1 NEW_LINE DEDENT if ( arr2 [ i ] == 1 ) : NEW_LINE INDENT arr2_one += 1 NEW_LINE DEDENT elif ( arr2 [ i ] == 0 ) : NEW_LINE INDENT arr2_zero += 1 NEW_LINE DEDENT DEDENT if ( arr1_one != arr2_one or arr1_zero != arr2_zero ) : NEW_LINE INDENT print ( " No " ) NEW_LINE return NEW_LINE DEDENT for i in range ( N ) : NEW_LINE INDENT count = count + ( arr1 [ i ] - arr2 [ i ] ) NEW_LINE if ( count < 0 ) : NEW_LINE INDENT print ( " No " ) NEW_LINE return NEW_LINE DEDENT DEDENT print ( " Yes " ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr1 = [ 0 , 1 , 1 , 0 ] NEW_LINE arr2 = [ 0 , 0 , 1 , 1 ] NEW_LINE N = len ( arr1 ) NEW_LINE canMakeEqual ( arr1 , arr2 , N ) NEW_LINE DEDENT