Check if original Array is retained after performing XOR with M exactly K times | C ++ implementation for the above mentioned problem ; Function to check if original Array can be retained by performing XOR with M exactly K times ; Check if O is present or not ; If K is odd and 0 is not present then the answer will always be No . ; Else it will be Yes ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; string check ( int Arr [ ] , int n , int M , int K ) { int flag = 0 ; for ( int i = 0 ; i < n ; i ++ ) { if ( Arr [ i ] == 0 ) flag = 1 ; } if ( K % 2 != 0 && flag == 0 ) return " No " ; else return " Yes " ; } int main ( ) { int Arr [ ] = { 1 , 1 , 2 , 4 , 7 , 8 } ; int M = 5 ; int K = 6 ; int n = sizeof ( Arr ) / sizeof ( Arr [ 0 ] ) ; cout << check ( Arr , n , M , K ) ; return 0 ; }