FizzBuzz -- famous simple coding interview question

Simple code -- a little loop and a little logic

Idea -- experienced people can write it instantly

Simple test for at least moderate experience

Alternately .. weed out beginners

Here -- a series of problems, playing on FizzBuzz themes

Build up to something more difficult than classic FizzBuzz

Some constructive advice

Here is a little discussion and a series of live practice problems based of the famous FizzBuzz problem. FizzBuzz is a kind of famous introductory programming interview question. It's not deep or difficult; it just combines a little loop code with a little logic code. The idea is that someone with practice writing loop and logic code can write the solution out very quickly, so it makes a good first question to establish basic coding fluency. (See Constructive Advice below on this.)

FizzBuzz Problem Statement

Based on a traditional English children's game

Print the numbers 1..100

For multiples of 3, print "Fizz" instead of the number

For multiples of 5, print "Buzz" instead of the number

For multiples of 3 and 5, print "FizzBuzz" instead of the number

Here: fill an array instead of printing + some other complications

So just for fun, here's a graduated series of problems that play on the same themes as FizzBuzz, working up to a slightly more complicated version of the FizzBuzz problem itself:

The FizzBuzz problem here is a little more complicated than the original, since we make you assemble the results in an array instead of just printing. We also specify arbitrary start and end numbers which enables a more interesting variety of tests.

Why is that someone with a lot of coding experience can just sit down and write FizzBuzz basically instantly? It's just practice. By the time you have written (and debugged!) hundreds of loops and hundreds of if-statements ... any new problem looks a bit like something you've solved before. There are not that many patterns.

The good news is, it's just practice! It's pretty quick to go through a bunch of CodingBat practice problems. I promise you, once you've solved 10 problems, the next 10 will go a lot faster. If you are feeling unsure of your coding ... just do the practice and be done with it.

Practice, practice, practice!

CodingBat.com code practice. Copyright 2013 Nick Parlante.