Make all array elements equal by replacing triplets with their Bitwise XOR | Function to find triplets such that replacing them with their XOR make all array elements equal ; If N is even ; Calculate xor of array elements ; Traverse the array ; Update xor ; If xor is not equal to 0 ; Selecting the triplets such that elements of the pairs ( arr [ 0 ] , arr [ 1 ] ) , ( arr [ 2 ] , arr [ 3 ] ) . . . can be made equal ; Selecting the triplets such that all array elements can be made equal to arr [ N - 1 ] ; Selecting the triplets such that elements of the pairs ( arr [ 0 ] , arr [ 1 ] ) , ( arr [ 2 ] , arr [ 3 ] ) . . . can be made equal ; Selecting the triplets such that all array elements can be made equal to arr [ N - 1 ] ; Driver code ; Given array ; Size of array ; Function call
def checkXOR ( arr , N ) : NEW_LINE INDENT if ( N % 2 == 0 ) : NEW_LINE INDENT xro = 0 ; NEW_LINE for i in range ( N ) : NEW_LINE INDENT xro ^= arr [ i ] ; NEW_LINE DEDENT if ( xro != 0 ) : NEW_LINE INDENT print ( - 1 ) ; NEW_LINE return ; NEW_LINE DEDENT for i in range ( 0 , N - 3 , 2 ) : NEW_LINE INDENT print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( i + 2 ) , end = " ▁ " ) ; NEW_LINE DEDENT for i in range ( 0 , N - 3 , 2 ) : NEW_LINE INDENT print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( N - 1 ) , end = " ▁ " ) ; NEW_LINE DEDENT DEDENT else : NEW_LINE INDENT for i in range ( 0 , N - 2 , 2 ) : NEW_LINE INDENT print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( i + 2 ) ) ; NEW_LINE DEDENT for i in range ( 0 , N - 2 , 2 ) : NEW_LINE INDENT print ( i , " ▁ " , ( i + 1 ) , " ▁ " , ( N - 1 ) ) ; NEW_LINE DEDENT DEDENT DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 4 , 2 , 1 , 7 , 2 ] ; NEW_LINE N = len ( arr ) ; NEW_LINE checkXOR ( arr , N ) ; NEW_LINE DEDENT