here is the my approach there is simple i converting both numbers into binary at once and parallel i checking the the bits are equal or not, if its equal not need for count increment otherwise increasing the count in above statement and given explanation we can easily assess when bits are different need to count here is the code below for clear understanding, one more thing is it takes time complexity 3ms there so much optimal solutions there it can easily understand
When you understand this problem of logic solve this
CODE EXPLANATION
in we declared the count to 0 int count=0; and in while loop we use logical or because if there is any number reduced zero but not another one is not reduced to zero, in that case we placed the or while(n>0||m>0) as we said the if condition if(n%2!=m%2) when there is different number the count gets increment count++; and the number is reduced in binary format i already told my previews post how the number converted into binary
When you understand this problem same similar
Question by click here
0 Comments