Can we use this approach for even frequencies also?

If we have an array of numbers where all occurs twice except 1 number, then we won’t even be needing to do modulus, the sum itself will be cancel out for the numbers occurring twice.
You getting my doubt?
eg 1 0 1 0, 1 0 1 0, 0 1 1 1 it will be= 0 1 1 1
and If i m not wrong this is what xor is?

@namanmittal0007
all elements occur twice, except 1 element, that occurs only once. Thir problem is unique-number-1 and it is also there in the course. The approach here is to take XOR of all numbers, so you are left only with the element with frequency 1.

Dont forget to mark your doubt as resolved :slight_smile:

i know there exist a dedicated video for the question but i am asking somthing different i am asking for a different approach and wants to know that the approach i am thinking of that same with what bhaiya taught in the unique no 1 video?

@namanmittal0007 what approach are you telling? Can you explain properly by taking one example? How will the sum cancel out without taking modulus??

okay, arr={14,14,6}
a=1 1 1 0 =14
b=1 1 1 0 =14
c=0 1 1 0 =6

=0 1 1 0=6

@namanmittal0007 so from my understanding, you are only considering the “sum” part and discarding the “carry” from the addition? Or are you considering the carry too? I think you should discard the carry and then it should work okay

for example

1 1 0 1
1 1 0 1
0 0 1 0 
=======
0 0 1 0 (without carry)
1 1 0 0 (with carry)

yeah i was thinking of without carry, now the big question is how to do this ?
by extracting each bit from the no like we did for unique no 3 and then converting to decimal or there’s some other way too ?

@namanmittal0007 See now to even take sum like this, you can either use boolean algebra but that can be too hectic and it will be difficult to understand if you are not already familiar with it. Otherwise, you will have to take sum % 2 to do the sum of binary numbers and make the sum binary as well, so it will basically become the same approach only.

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.