The Fizz-Buzz Programming Test

A lot has been said about the FizzBuzz programming test used in interviews. It's a decent litmus test measure of testing a few key capabilities in a developer i.e. (a) knowledge of programming constructs (iterations/conditionals) (b) algorithm / logic and (c) thinking process

The problem statement goes as follows.

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 are few scenarios how it may play out during interviews.

Scenario A.

Interviewer: States the problem statement.

Applicant: hmmm....How do I do multiples?

Interviewer: (grrrr.. Out!.) You'll be hearing from our hiring manager. Nice meeting you.

Scenario B

Applicant: well, I think in the loop .. if (number * 3 = 5) print something

Interviewer: (Out!) You'll be hearing from our hiring manager. Nice meeting you.

Scenario C

Applicant:     

for(int i=1; i<=100; i++)

{ if (i % 3 == 0)

{ Console.WriteLine("Fizz");

if (i % 5 == 0) Console.WriteLine("Buzz");

if (i % 3 == 0 && i % 5 == 0)

Console.WriteLine("FizzBuzz");

else

Console.WriteLine(i);}};

Interviewer: (well, I suppose you get points for trying but NO, it won’t work. Will print Fizz Buzz FizBuzz for 15.) You'll be hearing from our hiring manager. Nice meeting you.

Scenario D

Applicant:      

for(int i=1; i<=100; i++)
{

if (i % 3 == 0 && i % 5 == 0)

Console.WriteLine("FizzBuzz!");

else if (i % 3 == 0) Console.WriteLine("Fizz");

else if (i % 5 == 0) Console.WriteLine("Buzz");

else Console.WriteLine(i);

}

Interviewer: It works! Cool.

Scenario E

Applicant:

for(int i=1; i<=100; i++)

Console.WriteLine( ((i%3 == 0 && i%5 == 0) ? "FizzBuzz" : ( (i % 3 == 0) ? "Fizz": (i % 5 == 0) ? "Buzz" : i.ToString())));

Interviewer: hmmm... terse and concise but readability / maintainability?

Hired / needs more review? Your thoughts?

Related:

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

Scott Hanselman - You Can't Teach Height - Measuring Programmer

Coding Horror: FizzBuzz: the Programmer's Stairway to Heaven

Share

One thought on “The Fizz-Buzz Programming Test

  1. Like the Imran quote on Scott's site "this kind of test won't identify the great programmers, but will expose the weak ones".

    If a candidate wrote version E, I would give them points for knowledge of the ternary operator and terseness. But I would ask follow up questions about maintainability and coding standards.

    An analogy is that the ability to write a quine or an obfuscated c program is an indicator of programming competency.

Comments are closed.