Jane Street

  www.janestreet.com
Work in HR? Unlock Free Profile

Jane Street Trader Interview Question

I interviewed in New York, NY and was asked:
"What is the sum of the digits of all the numbers from 1 to 1000000? This is different from the sum of the numbers. For instance the sum of the numbers from 1 to 10 is 55 whereas the sum of the digits is 46."
Tags: brain teaser, math
Add Tags [?]
Answer

Part of a Trader Interview Review - one of 421 Jane Street Interview Reviews

Answers & Comments

12
of 15
votes

The main idea is that if you write all the numbers from 0 to 999999 down as six digit numbers (possibly prepending zeros) then all digits appear the same number of times. So, its digit appears exactly 6 x 1000000/10 = 600000 times. so the result is 600000x 45 +1 (+1 for the number 1000000)

- Interview Candidate on May 2, 2012
0
of 9
votes

Maybe I'm reading it wrong, but isn't the sum of the digits of 1-10 just 11? 1 digit for 1-9, 2 digits for 10-99? So it's 9+90*2+900*3+9000*4+90000*5+900000+6

- Kevin on May 19, 2012
3
of 19
votes

no, I think the easy way to solve it in your head is to remember that when adding all digits 1 to 100, you have 50 pairs: 1+100, 2+99, etc. Each pair is 101, times 50 is 5050.
1 to 1000 would be 500500
so 1 to 1,000,000 would be 500,000,500,000
Pretty cool, huh?

- scott on May 24, 2012
5
of 5
votes

scott, dude you should add digits not the numbers, so 99+2 = 18+2 =20. not 101

- mokhlos on Jun 28, 2012
2
of 2
votes

Scott's answer from May 24 is the correct way to think about it if summing the numbers.

- David on Aug 26, 2012
2
of 4
votes

The answer is 27,000,001 - if you do it programatically the operation is a simple map reduce - simply map a digit sum function across the list of values [1, 1000000] and then reduce an addition operator across the result.

Python Proof:
>>> sum(map(lambda n: sum(map(int, str(n))), xrange(1, 1000001)))
27000001

- nb on Sep 5, 2012
0
of 5
votes

21085156

- tmbtw on Sep 27, 2012
2
of 6
votes

Don't mind the above answer. I read the question wrong.

- tmbtw on Sep 27, 2012
3
of 6
votes

Each digit will appear 1+10+100+1000+10000+100000 times. so the answer is 111,111*45+1=4444440+555555+1=4999996

- John Doe on Nov 9, 2012
3
of 3
votes

nb is right. Another way you can think about it easily is if you want the digits from 1 to 1,000,000 then each digit should appear 1/10 * 1,000,000 times.
So

100,000 x 6 (for each place value) x 45 (the sum from 1 to 9) + 1 (for the 1 million)
27,000,001

- FM on Dec 2, 2012
1
of 2
votes

I think John Doe is right.

- KR on Dec 4, 2012
9
of 9
votes

27,000,001 is what I got. Think of each number as a 6 digit number. The average number each digit could be from 000,000 to 999,999 is (9+0)/2=4.5. Since the average of each number is 4.5 and there are 6 digits the average sum of the digits for a 6 digit number should be 4.5*6=27. There are 1 million numbers from 000,000 to 999,999 so the sum of the digits from 000,000 to 999,999 is 27,000,000. Subtract the digits of 000,000 which is just 0 and add the digits of 1,000,000 which is just 1 to get 27,000,001.

- KG on Jan 16, 2013

To comment on this question, Sign In with Facebook or Sign Up

Tags are like keywords that help categorize interview questions that have something in common.