using xor, in this case, is favorable but isn’t it only because we have all other numbers twice and that way A^A becomes 0.
what if we had those all numbers thrice and we had to then find the unique number without using arrays. what should we do then ??
XOR usage specificity
@prateeknanda10 to do this in O(1) memory complexity, you can have an array A of size 32 (this is still O(1) as memory size is small and known) then for every element, increment the ith position of A if ith bit is set.
Now finally take modulo of every element of A, all remaining non zero elements form our required number, make number using the non zero numbers of array.
If this resolves your doubt mark it as resolved.
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.