First off, I have no idea why this question works so well. I don't even have a good theory. All I have is an incredible correlation between answering this question correctly and being a really strong programmer.
The question was suggested to me by someone I respect a lot. I replied that it seemed too easy but he suggested I try it. He's a smart & imaginative guy so I started asking it of people I interview.
The interview process at virtually every company I have worked at has been 3 – 4 hours long. We ask basic programming, we ask brain teasers, we have them bring in some code they are proud of and spend 45 minutes having them take us through what they did and why. And 99% of the time, getting this question right or wrong predicts if they will pass the 3 – 4 hour process.
Question: For the integers between 0 and 100 (i.e. 1, 2, 3, …, 100) – how many have the digit 7 in them?
Answer: In the first comment below – answer it before reading below.
Keep in mind programming skill is just one of the skills you need to interview for (albeit, a critical one). So this is not the single question that answers if you should hire someone. You still need to determine if they work well with others, can make the right compromises and trade-offs to deliver a quality product – on time, etc. But to measure their technical ability, if I only got to ask one question, this would be it.
As to why it is such a good predictor – I have no idea. But before you dismiss it, try it.


The answer is: 19. You have 7, 17, ... 97. And you have 70, 71, ... 79.
The most common answer is 10 - the 7, 17, ... part.
The second most common answer is 11 - they also get 70.
Some people say 20 (counting 77 twice) - I consider that a correct answer for the purpose of the interview.
So, did you get it?
Posted by: David Thielen | 01/17/2010 at 08:38 PM
I did get 19 but had to remove my shoes to get there. Is that bad in an interview?
Posted by: ben logan | 01/18/2010 at 09:41 AM
I get 19 in about 2 seconds. That makes me feel great!!, and yes. i think am a good developer
Posted by: carlo | 01/18/2010 at 01:58 PM
Dumb logic tricks don't mean much when looking for a competent programmer.
Posted by: Mark | 01/18/2010 at 02:23 PM
Kindergarten admission test?
Posted by: Giorgio Sironi | 01/18/2010 at 02:29 PM
Congratulations on using the most derided writing tool EVER!!!!
Posted by: mw | 01/18/2010 at 02:55 PM
I think being able to solve this "dumb logic trick" speaks to your ability to fully cover corner test cases, which helps you write correct code faster. We all know that one programmer who would miss the special cases for 7's the first time, but check his code in anyway. Then when he gets a bug report saying there's a problem with 7's, he checks in a fix for a 7 in the one's digit. The bug report gets sent back to him again to handle the 70's, then yet again to handle the duplicate 77. In a real program, it's conditions like full buffers, empty buffers, null pointers, etc., but the mode of thinking is the same.
Posted by: Karl Bielefeldt | 01/18/2010 at 03:05 PM
I got 19 in a few seconds, then spent the next several minutes trying to find something I'd missed!
Posted by: AJ Finch | 01/19/2010 at 03:12 AM
Nice post. Thanks
Posted by: SMiGL | 01/19/2010 at 03:35 AM
Is this really The Best Programming Interview Question – ever! ? really? A high school kid can do this few seconds.
Posted by: kittu | 01/19/2010 at 08:37 AM
What nonsense.
Posted by: Anonymous | 01/19/2010 at 11:09 AM
18. Missed by one. I was over-protective in not counting 77 twice. :)
Posted by: Zecc | 01/19/2010 at 01:51 PM
this was really a dumb article by being way ahead with any other competition
Posted by: deeproot123 | 01/19/2010 at 06:39 PM
it was really a high school level question solvable in few secs.
from now on, dont ever put your article on dzone etc
just stop wasting ppl time.
u dumbo
what a height of stupidity of having such a title
Posted by: deeproot123 | 01/19/2010 at 06:42 PM
I don't know why so many people think there are only 19 sevens, I think the answer is really 20. 7,17,27,37,47,57,67,70,71,72,73,74,75,76,77,78,79,87,97.
Posted by: Raj | 02/16/2010 at 11:40 AM
Interesting... for sure someone with an answer not equal 19 would be a problematic programmer. What if you ask the candidate to write a program that will return that value and test it? Could be a good test too...
Posted by: Qatan | 01/17/2011 at 12:39 PM
I have read couple of good article about conducting interviews and it seems they all favor for technical properties. I agree technical skill is important but at the same point soft skill, behavioral skill, attitude and personal human quality are more important because you can fill the gap in technical knowledge but believe me you can't change the other qualities I have listed and plus point is person can't fake those qualities.
Posted by: programming interview question | 06/19/2011 at 03:41 AM