Regarding the error
Testcases are not passing
you are unnecessarily making this code complicated.
in this question you have to just count the number of set bits and that will be the answer of the question.
here your code is printing the correct result for the sample testcase but failing fot all the other test cases.
also that appoach which i told you is very optimised.
Here for your reference i am attaching the code:
if you have any doubt you can ask here:
Happy Learning !!
ok got it
But what is the error in my code???
Bad complexity eventually end up with these error because of incomplete answer.