Jane Street interview question

How many "1's" are are there between 0 and 1000000?

Interview Answers

Anonymous

6 Feb 2014

There are 9^6 numbers that don't have any digits with 1 in them. So the answer is 10^6 - 9^6.

2

Anonymous

17 Feb 2014

The question is unclear. I thought it meant when you write the numbers out, how many ones appear. For example, in the numbers 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, there are a total of 4 ones that appear, because 11 has 2 ones. In this case, the answer is: (6, 1) * 10^5 + (6, 2) * 10^4 + (6, 3) * 10^3 + (6, 4) * 10^2 + (6, 5) * 10 + (6, 6) + 1 where (n, k) denotes n choose k. To see why, note that we can form six blanks: A B C D E F -- where each blank can take on values 0-9. This represents a valid number between 0 and 999 999. The total number of ways to have k ones is (6, k) * 10^(6-k). So, sum over this quantity from 1 to 6. Finally, we have to add 1 to the result, since 1 000 000 has one 1, and it can't be represented by A B C D E F.

1