Interview Question: Digital Madness

Sample Question #256 (brainteaser)
Write down the integers between 1 and 9999 as one concatenated string, i.e., "123456789101112…".
1) How many digits do we have in this string?
2) What’s the 10,001-st digit in this string?
This entry was posted in Sample Qs. Bookmark the permalink.

5 Responses to Interview Question: Digital Madness

  1. Brett says:

    Here’s a bonus question:
    How do you solve this problem using a computer program?

  2. Unknown says:

    I think the last number should be 2777 instead of 2778.Does this kind of question really show up in quant interview?

  3. Brett says:

    steve: you’re right, thanks!
    Yes, this kind of question gets asked at interviews. It tests how you think carefully under stress.

  4. Richard says:

    2) question, 10001-2889=7112.  Since all numbers after 2889 are 4 digits, we can use 7112 to divide 4 and get 1778.  Teh 10001 digit will be the last digit of the 1778th 4digit numbers, which starts with 1000.  So this number is 2777.  Not sure if this matters, but I read that the question is asking the 10001 digit, so I think the answer is just 7.By the way, very good job in your book Brett! Practical and thanks for all your effort in the book and here for helping quant wannabe.  As a Chinese, I am truly proud of what you have done!

  5. Brett says:

    ANSWER [corrected and updated, thanks to steve and richard]
    1) There are 9 single-digit numbers, 90 two-digit numbers, 900 3-digit numbers, and 9000 4-digit numbers between 1 and 9,999. So the total number of digits is: 9×1+90×2+900×3+9000×4 = 38889.
    2) Since 9×1+90×2+900×3=2889 < 10001, so we know the number that contains the 10,001-st digit must be a four-digit number. 10001-2889=7112, and 7112/4=1778, so the number containing the 10,001-st digit is the 1778-th number starting with 1000, which is 2777. Since there’s no remainder from this division, we know the digit must be the 4th digit of the number (can you see why?), which is 7.
    [Pretty cool question, huh?]

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s