One of the basics of Computer Science is knowing how numbers are represented in 2's complement. Imagine that you write down all numbers between A and B inclusive in 2's complement representation using 32 bits. How many 1's will you write down in all ?
Two integers A and B
The number of 1s
-2^31 <= A <= B <= 2^31 - 1
Find the asymptotically optimal algorithm.