this algo work for only 2 unique number or in general for any number of unique numbers in an array?
Unique number 2
According to the question, it was given that all numbers are present twice except 2 numbers which are only once. The solution given in the lecture will work only for the case with 2 unique numbers.
and how we are deciding which set bit position we have to find??
The position of the first set bit from back in the number will be considered.
how we got the intiution to do it like this??
Earlier you performed Xor and now you have to get the first set bit in that result. As XOR is " ODD 1s detector" so a set bit would indicate that there are odd number of 1s, remaining are 0s. So the numbers can be differentiated based on this criteria. Surely some numbers will have 0s at that position and some will have 1s.
If the numbers are repeating twice and there are 3 distinct element in an array for example {2,2,4,4,6,7,8}how to find distinct elements by bitmanupulation…??
if the numbers are repeating twice and there are 3 distinct element in an array for example {2,2,4,4,6,7,8}how to find distinct elements by bitmanupulation…??
You would have to do that by brute force. No such way using bit manipulation.
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.