Check if two arrays can be made equal by swapping pairs of one of the arrays | C # program for the above approach ; 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 , print " Yes " . Otherwise " No " ; Driver Code ; Given arrays ; Size of the array
using System ; class GFG { static void checkArrays ( int [ ] arr1 , int [ ] arr2 , int N ) { int count = 0 ; bool flag = true ; for ( int i = 0 ; i < N ; i ++ ) { if ( arr1 [ i ] != arr2 [ i ] ) { if ( arr1 [ i ] == 0 ) count ++ ; else { count -- ; if ( count < 0 ) { flag = false ; break ; } } } } if ( ( flag && ( count == 0 ) ) == true ) Console . WriteLine ( " Yes " ) ; else Console . WriteLine ( " No " ) ; } static public void Main ( ) { int [ ] arr1 = { 0 , 0 , 1 , 1 } ; int [ ] arr2 = { 1 , 1 , 0 , 0 } ; int N = arr1 . Length ; checkArrays ( arr1 , arr2 , N ) ; } }