in the question of two unique numbers how did we get to the logic that after doint XOR of all numbers now we have to XOR the numbers whose 2nd bit is set?
XOR operation on finding two unique nos
no…where all numbers occur twice except two
2,1,3,5,1,7,3,2
this example i was talking about?
just want to know the thought process behind the logic
hey @ynikhil1999, when you take x-or of all the numbers, you will get answer which nothing but x-or two unique number (say ans). Now you have separate the these number from there x-or.
now the thoughtprocess is, if xor of two digits is 1 then there must me one digit which is 1 (1 x-or 0=1 and 0 x-or 1=1). Out of two number there must be one number which has 1 at the position of last set bit in ans.
Example ans=011 than one of the number be like xx1 (x=dont care).
Example ans=010 than one of the number be like x10 (x=dont care).
hence we are dividing the array into two parts such that part one has 1 at the particular position.
hey @ynikhil1999 , if your query is resolved. Please mark this doubt as resolved and rate me on the basis of your experience.
rating option will appear when to mark this doubt 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.