Solving the Fizz-Buzz Question

Coding Horror: Why Can't Programmers.. Program?.

It's a shame you have to do so much pre-screening to have the luxury of interviewing programmers who can actually program. It'd be funny if it wasn't so damn depressing.

He quoted Irman's FizzBuzz question, a trivial programming problem but surprisingly has stumbled many job applicants. Here is the requirement:

Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

Here's an example solution in Python:

for i in range(1, 101):
    print ('FizzBuzz' if i % 15 == 0 else
           'Fizz'     if i % 3 == 0 else
           'Buzz'     if i % 5 == 0 else

I actually find Irman's comment exaggerating from my own experience, when he said:

Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes. Want to know something scary? -- the majority of comp sci graduates can't.

I am not sure where he sourced his programmers from, but it is definitely not my own experience. In fact I seriously doubt you can be a comp sci graduate without being able to solve trivial programming task such as Fizz-Buzz.

Over the last 6 years of hiring, we do ask our applicants to solve programming tasks. However, instead of asking them to write a 10 line program to resolve something trivial, I normally like to ask them for a sizable code chunks -- something that have done in the past in a different project or something they want to spend 2-3 hours to do after the face-to-face interview -- that doesn't matter. We care more about how problems are solved, the style code is laid out, the depth of thinking putting into catching exceptions, etc, than actually solving the problem itself, as we found most programming exercises are either too trivial (does not filter out bad programmers), too difficult (too focused on optimization and problem solving) or are too big (take way too much applicants' time).

In an interview we had last month for example, I have the following programming task for an application to do after the interview:


A command line mashup tool for Google and Alexa.

Some search keywords.
Google PageRank and Alexa Traffic Rank for the top 10 sites that match the keywords in Google Search.
~$ myscript "programming"
Google PageRank: 7 Alexa Rank: 12
Google PageRank: 6 Alexa Rank: 189177
Google PageRank: 9 Alexa Rank: 4076
Google PageRank: 6 Alexa Rank: 42020

(Note: the job is basically doing financial data mash-ups, thus the way the programming task was designed)

He came back later with his 150 line Perl solution that uses regexp to scrape the Google SERP, and a bit of XML to process AWS result -- not too shabby in solving the problem, but then again it is the programming style we are looking for -- whether code is structured well, well presented, and the problem approached at the right angle. I won't say whether he got the job.

Seriously. If the majority of the job applicants can't solve simple programming tasks, it is likely that you are using the wrong recruitment agent...