sir i am not able to understand that in { 1,2,3,4,3,2,1} , how can we find unique number by traversing with xor of continous elements. the xor can cancel only continuous elements which are same. but in example, we have 1^2=3 then it will cancel with next 3 , then how other 3 can be cancelled.
they can be cancelled with xor when the repeating elements are together and even times.
Unique number using xor operator
xor cancel the element which are same
for this example
i am showing step by step xor results
1^2=3
3^3=0
0^4=4
4^3=7
7^2=5
5^1=4
so in end we get 4 hence we can say that all same nos are cancel
you can think it like that
1+3+5-1-3=5
all positive and negative nos are cancled out at end
in any way you add them
i hope you understand it now
if not feel free to ask
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.