testcase is not passing
Playing with bits
Hi @vaishnavtannu
You are getting time limit because you are using same variable that is i in both for and while loop and every time you are calculating number of set bits in i you are reducing it to 0 and then for loop increments that i to 1 and hence your loop keeps on going without termination.
I have changed your code a little bit have a look :
Got your point but now the code is giving output 1 1 instead of 1 17 in the sample test case while it got submitted correctly.
Hi @vaishnavtannu
The code that i have shared with you is showing 1 17 only as the output to the sample case. Refresh your page and try to run it again it will show the correct ans only.
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.