Playing with Bits


Why my code is not working?

It is giving TLE because in the for loop in line 25, you are using the same j variable to count the set bits as well. So its value always becomes 0 after set bits are calculated. And this gives TLE.
To resolve this, declare any other variable and initialise it with j to count the number of set bits.

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.