We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
my approach was converting the number into binary number and counting the number of 1,0 in each digit... but in the middle of analyzing, i realized that i don't have to convert... OR operation and multiplication is enough...
let's get started..
from xor property if there is odd number of 1 for xor operation, then the result of xor returns 1...
in first step, since number of 0 is indepedent on the result, considering the number of 0 occurence, we have to take 2 ^ (# of 0) into account...
in second step, we have to reflect the effect of (# of 1)... as i mentioned above, odd numbers of 1 will return 1.. basic combination mathmatics, 0CN + 1CN + 2CN ... NCN = 2^N and the case for odd is 2^N-1...(this N is general term.. not total number of elements.. don't be confused)
finally, merging of 0 and 1 effects(product) will be 2 ^ (total number of elements minus 1)..minus 1 part comes from the effect of 1, only odd part...
this will hold for all cases with more than 1 bit in the digit... the meaning of this is OR operation so.. OR of all the elemets and multiply by 2^(N-1).. after applying modular operation for the problem condition, you can pass the problem...
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Xoring Ninja
You are viewing a single comment's thread. Return to all comments →
my approach was converting the number into binary number and counting the number of 1,0 in each digit... but in the middle of analyzing, i realized that i don't have to convert... OR operation and multiplication is enough...
let's get started..
from xor property if there is odd number of 1 for xor operation, then the result of xor returns 1...