if we already have a mask as res( first xor calculation )why we calculate that again. It is same as mask
Calculating mask
Hello @amanpunetha,
When you perform the first xor i.e. you are left with a^b where a and b are the required unique numbers.
The idea used here is to divide the entire sequence into two groups, one containing a and other containing b.
To separate them into two groups,
we are finding the position of first set bit from right in the xor i.e. a^b.
Then, mask is created by right shifting the 1 by ‘pos’ positions.
Answer to your question:
No, the mask and xor will not necessarily be the same always.
Example:
xor= 100100
mask=000100
Suggestion:
Re-watch the video now.
Hope, this would help.
Give a like if you are satisfied.
but if i iterate again to loop again perform
if((result_xor | sum[i]) ==sum[i]){
result1=result1^ sum[i];
}
else{
result2=result2 ^ result[2];
}
simply i can find my ans .
not to calculate mask again
Hello @amanpunetha,
Consition: result_xor | sum[i]) ==sum[i] will never satisfy.
Please, give an example in support of this.
array : 5 3 1 2 5 1 7 2
result_xor = 4
result1=0,result2=0
if(result_xor | sum[i]) ==sum[i]):
so: 4 | 5 ==5 it will xor with result 1 same for 5 and 7 further
and 4 | 1 !=1 it will xor with result 2 same for 1 2 3 further
result1 will give 7
result2 will give 3
Hello @amanpunetha,
Your approach will fail for test cases like:
For the sequence:
1 2 2 3 3 4
Unique numbers:
1 = 0 0 1
4 = 1 0 0
xor = 5 (1 0 1)
5 | 4= 1 0 1 (this is not equals to 4 i.e. sum[i])
5 | 1= 1 0 1 (even, this is not equal to 1 i.e. sum[i])
How would you separate them now?
thank you
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.