Suppose the number 11. The answer should be 8+2+1=3
I will subtract 2^(int(log2(11))) from 11. that will give me 3.
Again with 3, subtract 2^(int(log2(3))). That will give me 1. and again do the same with 1 that will give us 0. So you see, the while loop runs 3 times, that’s our answer
Test cases failing
Don’t do anything on N just try to think this problem based on number of set bits present in N
Think for these test cases only 11,3,15,21 think for these numbers.
Also this is your updated code it will work too.
Seems that it is equal to the number of set bits
Yes now you got it right. you will see it’s almost similar to this problem.
Yeah, observed it. It will take me some time to absorb it as an intuitive solution, thanks tho. :))
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.
https://ide.codingblocks.com/s/395232 could you see why is it still giving error?
(The Hulk problem)
See here