One developer interview question is asked or referred to so often for so long, it is almost a cliché: the FizzBuzz challenge. Though this challenge will appear very simplistic to those with some coding experience, it is designed to weed out people who cannot creatively use their coding knowledge to solve simple problems. See our thread on the rationale behind coding challenges for more info.
The History of the FizzBuzz Challenge
As the inventor of this challenge, Imran Ghory, states:
After a fair bit of trial and error I’ve come to discover that people who struggle to code don’t just struggle on big problems, or even smallish problems (i.e. write a implementation of a linked list). They struggle with tiny problems.
So I set out to develop questions that can identify this kind of developer and came up with a class of questions I call “FizzBuzz Questions” named after a game children often play (or are made to play) in schools in the UK.
This challenge is based on a children's game used to teach division. Children sit in a circle. The player going first will say one, followed by the player next to them (going clockwise or counter-clockwise) saying two, and so on, adding one each time. However, any number divisible by three is replaced by the word Fizz, any divisible by five by the word Buzz, and numbers divisible by both three and five become FizzBuzz. A player who hesitates or makes a mistake is eliminated from the game.
Turned into a code challenge, this becomes the FizzBuzz Challenge:
"Write a program that prints the numbers from 1 to 100. But for multiples of three print
Fizzinstead of the number and for the multiples of five print
Buzz. For numbers which are multiples of both three and five print
Try your hand at the FizzBuzz challenge: submit your answer below! It's not a true test of your abilities if you look at other people's answers below or Google for examples - try to solve this yourself as if you were in a job interview situation.
Remember to format your code!