FizzBuzz is simple enough that I'd expect them to be able to write the solution not only in pseudo-code, but in the language of their choice, ignoring syntax errors of course.
I don't see why you should expect 30 minutes to come up with the following solution:
for(int i = 1; i <= 100; i++)
{
string output = string.Empty;
if (i % 3 == 0) output += "Fizz";
if (i % 5 == 0) output += "Buzz";
if (string.IsNullOrEmpty(output)) output += i;
System.Console.WriteLine(output);
}
Yes, I could have used StringBuilder
to make string concatenation (as little as there is) slightly more efficient, or removed the concatenations by using if-elseifs instead. Hell, anyone who writes down string.IsNullOrEmpty
should be hired right then and there.
Add: I'm nervous as hell during interviews, but I don't think I'd have trouble with a question as simple as this one. Typically, I've been asked either much harder questions that I've choked on, or been asked such unimportant questions, such as the syntax for operator overloading in C++, that any simple Google search would return the answer in a real-world situation. It's a touchy subject for me, knowing I have to rely on the quality of the interviewer.
While it might not be possible in many environments, I think the optimal situation would be to sit the interviewee on a computer with the newest version of Visual Studio up and running, and say "Write a function that answers the FizzBuzz question. I'd just like to see your coding style."
I feel like it'd be a situation like this where'd I'd really shine, just because I've learned to love the FxCop guidelines:
/// <summary> Prints the numbers 1 - 100, writing Fizz when divisible by 3, and Buzz when divisible by 5 </summary>
public void PrintFizzBuzz()
{
for(int i = 1; i <= 100; i++)
{
string output = string.Empty;
if (i % 3 == 0)
{
output += "Fizz";
}
if (i % 5 == 0)
{
output += "Buzz";
}
if (string.IsNullOrEmpty(output))
{
output += i;
}
System.Console.WriteLine(output);
}
}
Yes, this is more work, but at least for me, it's much easier to visualize a solution with Visual Studio in front of me for such a trivial question than to write pseudo-code on a piece of paper. I do most of my work on a computer, not on paper, and I'm much more at-home in front of one. And doesn't this provide much more insight into the programmer's quality and their respect for readability?