Algo++ : playing with bits

In this question we have to find no. of set bits for each integer between a and b, and keep that adding in result . Is there any better approach to this tquestion

@amandahiya.3572
This is correct approach.
Alternatively , since there are many testcases involvedd , you could precompute the bits for each number and store them in an array so you do not have to compute the no of bits of same values again and again. You could directly he your sum from it.
Or you could also make a cumulative sum array where you compute the cumulative sum as you fill it and just subtract the lower bound sum from upper bound sum.
Try coding this out. You could use any of these approaches. Let me know if you need any help.

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.