Unable to understand the question

like if we have input as 23.
so the answer should be-8(if it jumps first to 16 and then jumps each step)
OR
the and answer should be 4(first to 16>20>22>23)

hello @aryaman.kumar26
answer should be 4.
and the steps are 16 -> 20 -> 22 -> 23 ( same as u mentioned )

video editorial -> hulk

image
this is not correct.
answer will always be number of set bit in n.
if u observe carefully.
for n-> 23 ( binary 10111)
16 -> 2^4 (10000)
then 4 steps from here i,e 16+4 .
4 -> 2^2
then 2 steps from here i,e 16+4+2 .
2->2^1
then 1 steps from here i,e 16+4+2+1 .
1-> 2^0.
if u obseve 16 + 4 + 2 + 1 is nothing but sum of weights of set bit in 23.
so u only need to print count of set bits.
cout<<builinpopcount(N) will be ur answer .

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.