
Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Maintain two integer variables, even and odd, to count the number of even and odd indices in the binary representation of integer n.
Divide n by 2 while n is positive, and if n modulo 2 is 1, add 1 to its corresponding variable.