Make Array elements equal by replacing adjacent elements with their XOR | C # Program of the above approach ; Function to check if it is possible to make all the array elements equal using the given operation ; Stores the XOR of all elements of array A [ ] ; Case 1 , check if the XOR of the array A [ ] is 0 ; Maintains the XOR till the current element ; Iterate over the array ; If the current XOR is equal to the total XOR increment the count and initialize current XOR as 0 ; Print Answer ; Driver Code ; Function Call
using System ; class GFG { static void possibleEqualArray ( int [ ] A , int N ) { int tot_XOR = 0 ; for ( int i = 0 ; i < N ; i ++ ) { tot_XOR ^= A [ i ] ; } if ( tot_XOR == 0 ) { Console . Write ( " YES " ) ; return ; } int cur_XOR = 0 ; int cnt = 0 ; for ( int i = 0 ; i < N ; i ++ ) { cur_XOR ^= A [ i ] ; if ( cur_XOR == tot_XOR ) { cnt ++ ; cur_XOR = 0 ; } } if ( cnt > 2 ) { Console . Write ( " YES " ) ; } else { Console . Write ( " NO " ) ; } } public static void Main ( String [ ] args ) { int [ ] A = { 0 , 2 , 2 } ; int N = ( A . Length ) ; possibleEqualArray ( A , N ) ; } }