What is right approach?

should I use divide and conquer?

https://ide.codingblocks.com/s/584915 it shows the right output but not clears any testcase

check for 11,
it’s output should be 3, that is jump on 8 then then 2 then 1
Hint: try to see a number in form of binary you will get it.

can this question be solved by divide and conquer approach? If yes then please provide hint

i don’t think so that it can be solved using DnC. You can tell me your intuition, will let you know at what case it will fail.

no of set-bits is the ans, right?

https://ide.codingblocks.com/s/585496 check this for D&C

yes,

this won’t work, check for 16, output will be 1.

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.