Check if two arrays can be made equal by swapping pairs of one of the arrays | Function to check if two arrays can be made equal or not by swapping pairs of only one of the arrays ; Stores elements required to be replaced ; To check if the arrays can be made equal or not ; Traverse the array ; If array elements are not equal ; Increment count by 1 ; Decrement count by 1 ; If flag is true and count is 0 , pr " Yes " . Otherwise " No " ; Driver Code ; Given arrays ; Size of the array
def checkArrays ( arr1 , arr2 , N ) : NEW_LINE INDENT count = 0 NEW_LINE flag = True NEW_LINE for i in range ( N ) : NEW_LINE INDENT if ( arr1 [ i ] != arr2 [ i ] ) : NEW_LINE INDENT if ( arr1 [ i ] == 0 ) : NEW_LINE INDENT count += 1 NEW_LINE DEDENT else : NEW_LINE INDENT count -= 1 NEW_LINE if ( count < 0 ) : NEW_LINE INDENT flag = 0 NEW_LINE break NEW_LINE DEDENT DEDENT DEDENT DEDENT if ( flag and count == 0 ) : NEW_LINE INDENT print ( " Yes " ) NEW_LINE DEDENT else : NEW_LINE INDENT print ( " No " ) NEW_LINE DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr1 = [ 0 , 0 , 1 , 1 ] NEW_LINE arr2 = [ 1 , 1 , 0 , 0 ] NEW_LINE N = len ( arr1 ) NEW_LINE checkArrays ( arr1 , arr2 , N ) NEW_LINE DEDENT