The FizzBuzz question is a very classical interview question asked in multiple interviews all around the world. There are many ways to do it in different languages. But in most general terms it definitely involves using 3 or 4 if/else if loops.There are fancy ways to do it if we go into Java 8 territory and such. But my main question is this:
- What is the logic behind this famous question?
- What are the interviewers looking for in the candidate when they ask this question?
- Do we know how to code basic stuff?
- Do they want to see our style of coding?
- Are they expecting optimization in this question? It's hard to try and optimize the code.
Here's a mathematical take on it:
if Loop count = 100
%15 calculation = 100
%3 calculation = 100 - 6 = 94
%5 calculation = 100 - 33 = 67
Total modulus calculation = 261 (100 + 94 + 67)