Sir i did not understand the logic why are adding the last all the bits of each number??? and than taking is mod 3 what exactly is the logic behind this???
Doubt in unique code 3
Each bit should be present in a multiple of three since if a number is repeated thrice, its contribution has to be three and same for all numbers but the number that will not be repeated thrice will give only 1 as contribution to that bit
So what the mod does is that it gives the count
So now there are 2 possibilities
either this bit is a multiple of 3, that means this bit is only set for all numbers which are repeated thrice
i.e. 3n for some n, so 3n%n gives the remainder when 3n is divided by n which is 0, which means this bit is not set in the required number
Second possibility on similar lines is that this bit’s count will be one extra than a multiple of three
which is 3n+1 and (3n+1)%3 = 1 which is the remainder
which means this bit is set in the required number
so that is the use of %
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.