Fizzbuzz is a toy algorithm that used to be popular in the context of technical interviews.

While I knew what it was, I was never asked to write a fizzbuzz until last week.

While the base algorithm is very simple, the point of the exercise is that the interviewer will add new rules to test how you update the code while keeping it readable and maintainable.

The base fizzbuzz implementation can be written as a typescript one-liner as

const fizzbuzz = (n: number)=>`${n%3 ? '' : 'Fizz'}${n%5 ? '' : 'Buzz'}`;

During my interview, I was asked to write fizzbuzz using any language of my choice, the interviewer noted that I could even use esoteric programming languages but advised me against because there would be lots of rules that would be hard to follow. This was to be expected given that the interview duration was up to 45 minutes and there is not much to talk about over a simple fizzbuzz. Changing the programming language after starting was also forbidden.

The first ruleset was revealed all at once and it was just the instructions on how to write a fizzbuzz:

  1. The algorithm must work at least for integers in the range 1-1000. We do not care for numbers outside that range.
  2. Using the browser is allowed but looking for FizzBuzz or entering pages that talk about FizzBuzz is not
  3. AI tools are forbidden
  4. The input is stored in an array named DATA
  5. Multiples of 3 make Fizz
  6. Multiples of 5 make Buzz
  7. Multiples of 3 and 5 make FizzBuzz
  8. FizzBuzz is mission-critical code. Bad inputs should not affect the output instead of catastrophically failing.
  9. Rules are always valid unless overridden by a new rule
  10. New rules will be revealed one by one. The candidate should note them as there won’t be shown again
  11. Breaking a rule does not immediately disqualify you, some rules can be broken as long as the offense is not too blatant subject to the interviewer judgement. Returning the wrong output is not acceptable though.