My issue
I have tried editorial’s approach to this problem but i don’t why can’t i pass all testcase.
Please help me
My code
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve(){
int n;
cin>>n;
vector<int>v(n);
for(int &i:v)
cin>>i;
int x=0;
for(int i=0;i<=60;i++){
int cnt=0;
for(int ele:v){
ele= ele+x;
if((ele & (1<<i) )!=0){
cnt^=1;
}
}
if (cnt==1){
x=x | (1ll<<i);
}
}
int verify=0;
for(int i:v){
verify^= (i+x);
}
if(verify){
cout<<-1<<endl;
return;
}
cout<<x<<endl;
}
signed main() {
// your code goes here
int t;
cin>>t;
while(t--){
solve();
}
return 0;
}
Problem Link: Xor Equation Practice Coding Problem - CodeChef