Suppose I have an array with 2n + 2 elements. n elements in the array occur twice, and the other two elements are unique. You must solve this in O (n) time and O (1) space. One solution is to use XOR. But I can’t understand this. Can someone help me with this or can give me a better solution?
Link to problem and solution this
First, note that a xor a == 0for each a.
a xor a == 0
a
Let's say you have two unique numbers - x,y.
x,y
xor , , x xor y ( ) "". (, , ), :(1) , .(2) , .
x xor y
, - ( "" ), .
xor , , .