Say , you are at index "i" . In a variable , say 'v' , store xor of all elements till "i" , so v = a[1]^a[2]^.....a[i] .

Now , if there is a "j" , such that j<i , and a[j+1]^a[j+2]^.....a[i] = k , it means z^k = v , where z = a[1]^a[2]^a[3]^...a[j] .

Now , z^k=v , hence , v^k = z , so we find the value of "z" by doing : v^k at given index "i" . (k is a constant) . After finding "z" , we need to know the index where xor of all elements from 1 to "j" was "z" . That index is "j" . We can store xor value and corresponding index in a map . We keep updating the map everytime , at every index , so we always get biggest possible value of 'j' . Answer is (i-j) for subarray ending at index 'i' .

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll ;
int main()
{
ll n ;
ll possible = 1e18 ;
cin>>n; ll k ;
cin>>k;
ll i = 1 ;
ll v = 0 ;
map <ll,ll> a1,b1 ;
ll good = 0 ;
a1[0]=0; //xor-value<--->index
while(i<=n)
{
ll x ; cin>>x;
v=(v)^(x);
ll m = (v)^(k);
if(b1[m]>=1)
{
good=1;
ll answer = abs(i-a1[m]);
possible = min(possible,answer);
}
a1[v] = i ;
b1[v]++;
i++;
}
if(good==0)
{
cout<<"NO";
}
else
{
cout<<possible ;
}
return 0;
}