Problem 338 · Easy

Counting Bits

dp[i] = dp[i >> 1] + (i & 1): the bit count of i is one more than the count for i with its lowest bit removed.

Open the interactive visualisation