we are creating a mask which is 1<<pos and let us assume pos = 2, also let us assume the same array but also with two 16’s. so when we do (16)&(mask) it is greater than 0 so it will give us true that at pos = 2 we have set bit in 16 but it is not true.
Doubt in mask in the above question
In this question, first take the xor of all values.
So your final xor value will be (num1)^(num2).
Now you have to extract the two numbers out of this value.
I did the following thing to get the two numbers -
sort(v.begin(),v.end());
for(int k=0; k<n-1; k=k+2)
{
if(XOR!=(XOR^v[k]^v[k+1]))
{
int d = XOR^v[k];
cout<<v[k]<<" "<<d<<endl;
break;
}
}
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.