End of Year Sale: Use Coupon Code END2025 to Get Extra 25% Off.
ans of length n + 1 to store the counts of 1's for each number from 0 to n.ans[0] to 0 because the binary representation of 0 has no 1's.n:
a. Calculate i / 2 and i % 2.
b. Set ans[i] to ans[i / 2] + i % 2.ans.