As a very first thing, I must say that I don’t like whiteboard coding exercises during the job interviews.
These exercises have almost never any relation to real-life programming problems (“Reverse a linked list?” If your reply is anything besides “linkedList.Reverse();”, your answer is wrong.). There are only a few dozen common whiteboard coding questions – and every candidate with a common sense will review those before the interview.
Finally, success with whiteboard coding seems to have next to no connection with the actual qualities of the candidate. And yes, this includes “solving a problem under pressure”.
I much prefer to give the candidates a small task, to do at home in 2..3h. This will give me much more information – what is his coding style? Can he write high-quality and well-commented code? Did he actually manage to finish all parts of the task – and if not, then why? Does he even want the position enough to do a proper job?
That all said, FizzBuzz does have one good use – it can be used to quickly weed out the candidates who cannot program at all. If they cannot do a simple logical exercise, and write a loop with a couple of if-clauses inside it, they really shouldn’t be hired as developers.
That is why ex-coworker Erti-Chris and I were rather surprised after reading “Tales of a Non-Unicorn: A Story About The Trouble with Job Titles and Descriptions” (reddit thread). A person claiming to be “designer/developer if there ever was one” goes “OMG MATH” and cannot solve FizzBuzz (which has almost nothing to do with math)?!
The “standard solution” using modulus:
Method Print is used repeatedly, it is the same everywhere:
But what if we don’t allow modulus to be used?
But what about not using neither round nor modulus?
(and also the same limitations as above, nutcase version. Proudly mine).
Still too easy. What about not allowing modulus, rounding, multiplication and division?
Amusingly, the last version is fastest of them all.
And by now we were out of time and bored of this. It was fun, though – a sort of minor coding kata.
All the code above can be seen and executed in dotNetFiddle, https://dotnetfiddle.net/84PodI