This is a quick code I wrote to try myself with an interview coding question from this article (Link). Basically it took me 10 min to write the whole thing (I tried to write it as neat and as elegant as possible in a quick time, so no comments included. Plus I’m a slow typer if I didn’t warm up first :P ).
Here is a quote from the article that should explain how the code works:
… 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.
In this game a group of children sit around in a group and say each number in sequence, except if the number is a multiple of three (in which case they say “Fizz”) or five (when they say “Buzz”). If a number is a multiple of both three and five they have to say “Fizz-Buzz”.
An example of a Fizz-Buzz question is the following:
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”.
Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes.
It would have taken me a couple of minutes alright, if I just wasn’t such a clean freak :)
You can see the code HERE.
You can download the code HERE.
Related Articles
No user responded in this post
Leave A Reply