Interview Answer

16 Answers

▲

21

▼

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

▲

1

▼

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

▼

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 500500so 1 to 1,000,000 would be 500,000,500,000Pretty cool, huh?

scott on May 24, 2012

▲

7

▼

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

mokhlos on Jun 28, 2012

▲

2

▼

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

David on Aug 26, 2012

▲

2

▼

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.

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

▲

0

▼

For arbitrary a=1,...,9 accounts the how many a's appear in the six digit number.

600000*(1+2+3+...+9)= 27000000.Then add the 1 from 1000000. The ans is 27000000.

lettuan on Nov 2, 2014

▲

0

▼

2.7 x 10^7 + 1

I&#039;m a genius on Dec 1, 2014

▲

4

▼

general rule:to 10^nanswer is 10^n * n * 4.5+1

here n=6, result is 27 000 001

Anonymous on Dec 5, 2014

▲

0

▼

1-1000000 same as sum of digits in 0 - 999999 then plus 1, treat 0 - 999999 as a 6 digit random number, then the digit of sum is sum of digit for each number: 1000000*(4.5*6)=27000000, so answer is 27000001.