This question has already been answered:
- Count the number of units in the number of 7 responses
There is a set of positive integers from 0..N.
It is necessary for O (N) to count the number of units of each number in the binary representation and put this info into the array!
Perhaps the question does not make sense, but you can do it quickly, instead of calculating the number of units of each number as a logarithm and get N log 14 (14 because the numbers do not exceed 10 ^ 4), you just need to do it in N.