# Practice question for interview - digits

I've bought a sample test to practice my upcoming interviews.

LVL 8
###### Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
There are 9 one-digit numbers and 90 two-digit numbers.
The rest are three-digit numbers.
This is more difficult. Not a visualization.

I get 1,000,051 employees.

1 to 9
20 to 29
30 to 39
40 to 49
50 to 59
60 to 69
70 to 79
80 to 89
90 to 99 is 189 digits

Then 100 to 999 is 270 digits
1000 to 9999 is 360 digits
10000 to 99999 is 450 digits
100,000 to 999,999 is 540 digits
1,000,000 to 1,000,029 is 210 digits

189+270+360+450+540+210 = 2019

1,000,030 to 1,000,051 = 21

Total is 2040.

Ends in 1 because no employee number 0

This one is tricky and you need to write down the groups to see.
Author Commented:
thanks, let me see.
I made an error in the last row.

Up to 1,000,029 is 2019 digits.

then 1,000,030 is 7, 1,000,031 is 7 1,000,032 is 7 and 2019 +21 = 2040

So the number is 1,000,032 (not 051).

Total is 1,000,032
Author Commented:
Thanks, John. I'll check it. Had to call it quits for the day :) thanks for all the help today.
\Commented:
If there are about 190 digits for the first 100, then the first 1000 should have a lot more than 270 digits, I would think.
\Commented:
100-109 --> 30 digits
110-119 --> 30 digits
...
190-199 --> 30 digits
______________________
100-199 -->10 * 30 = 300 digits
200-299 = 300 digits
900-999 = 300 digits
_________________________
100-999 = 9 * 300 = 2700 digits
\Commented:
since only 2040 digits are needed, and if there were 1000 employes, we would need over 2700 digits, then N < 1000.

Hope you can take it from here.
Commented:
There are less than one thousand

As you've already seen you are looking for the total number of digits used to count from "One" to "Total Number of Employees"

counting the first nine use one digit each 1, 2, 3, 4...

So to get to employee Nine you'll have used only 9 of the 2040 digits

Then from employee 10 to employee 99 you'll use two digits each time
That's another ninety employees (99 = 90 less the 9 you've already dealt with) so at two digits each that's 180 for 10-99 plus the 9 single digits

So you've used 189 digits to count from 1-99

Between 100 and 999 each employee number uses three digits at most that's 899 x 3 digits which = 2697

Your question only gives you 2040 digits to use so you know there are less than 1000 employees

So:
You have only 2040 digits to account for
To count the first 99 uses 189 digits

You know all the additonal employees will use three digits each:

Employee 100 = 190 digits used
Employee 101 = 191 digits used
...
and so one - but there's a quicker way to get to that mathematically.

Your questions all ask you to use logic AND mathematics, as they increase in complexity more thought about how you need to use simple math to get to a solution becomes needed.

If you have an option in a timed test to skip questions and return to complete them later pick off those you are certain of quickly and come back later to those that need more thought/reasoning.
According to the example provided, digits are not unique and re-used, so that changes how we calculate.
Commented:
This should be a 30s question with pencil and paper:

There are 9 one-digit numbers:    1 - 9 using 9 digits.
There are 90 two-digit numbers:  10 - 99 using 180 digits.

There are 2040 -189 = 1851 digits left for exactly 617 three-digit numbers starting at 100.

So I get 716 employees.

Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Commented:
Yes, it's a bit like buying numbers to stick on the front of their lockers.
It's a shame they didn't use leading "0"s :)
Author Commented:
The answers weren't right. But it's ok. If I get this on the test, I'll skip it.
\Commented:
>> Between 100 and 999 each employee number uses three digits at most that's 899 x 3 digits which = 2697
Off by one: If there are 999 employees, then (999 - 100 + 1) = 900 employees will have 3 digit numbers, in which case there are 900 x 3 digits = 2700 digits.

From this we conclude that 100 < N < 999.
\Commented:
>> The answers weren't right. But it's ok.

It looks to me like d-glitch is giving you the correct answer.

>> If I get this on the test, I'll skip it.
If you do not have time to answer all the questions, then skip the hardest ones, I guess. But, the point of this partitioning exercise is to see how well you think. I advise to show the partitioning that you learned here and come up with an answer even if it turns out to be wrong.

>> It's a shame they didn't use leading "0"s :)
In a real company, they probably would do that, or just start the numbering scheme with 10000 (reserved for the CEO). :)
\Commented:
Remember to check the answer in the interview if you are allowed the time.
CHECK

Suppose you have N = 716 employees.

1-9 employees     --> 9 digits
10-99 employees   --> (99 -  10 + 1) * 2 = 90*2 = 180 digits
100-716 employees --> (716 - 100 + 1) * 3 = 617 * 3 = 1851 digits

Add up the three partitions: 9 + 180 + 1851 = 2040 digits

The idea of sub-dividing a problem into smaller partitions is an important concept in problem solving. It is best to show your ability in this regard if you are writing on a whiteboard. Draw lines or boxes to show the individual partitions and work on each one separately.
Author Commented:
I put the answer in the test and I get incorrect. Let me try again.
\Commented:
Please give us the link for this online test whether it be practice or for credit.
BTW, this problem is quite a bit harder than your previous problem. As you can see, this problem even got some experts close but not quite on target. One of the pitfalls is to realize that when counting from 0 or from 100, you have to take special care because we are used to counting from 1.
Commented:
You can solve this by brute force in two columns of an Excel spreadsheet:
Put a 1 in Col 1, Rows 1-9, and a 2 in Col 1, Rows 10-99, and a 3 in Col 1, Rows 100-999.
Then do a running total in Col 2 and look for 2040.

This takes less than 2 minutes and confirms my answer.

You can also solve this programmatically with for-loops or recursion.
Commented:
I still make it 716 - if the given answer is 717 they are counting an employee zero!  (If 716 is coming up as "Incorrect" try 717 just for a giggle)

1-9 @ n=1 (9x1)  =9 numerals (9 staff)
10-99  @ n=2 (90x2) = 180 numerals (90 staff)

189 numerals used to cover  99 staff

number of numerals left to issue to staff 2040-189 = 1851

Each remaining staff member needs three numerals so (1851/3) = 617

These 617 people added to the other 99 = 716 staff
Author Commented:
yes, 716 is correct.  I just double checked.
Interesting because the practice hint says count ALL digits even if re-used.
Author Commented:
Helped me solve this one
How many digits are needed to assign numbers to 283 employees using the numbers 1 through 283?

741.
Commented:
That is correct.
Author Commented: