Feb 12, 2019

|

by: james

|

Tags: Coding Questions, Interviewing, Tech Tips

|

Categories: Hiring, Tech Tips

Why Do You Fizz Buzz?

Why Do You Fizz Buzz?

Almost every developer has heard of or been asked to implement Fizz Buzz – either in an introductory computer science class or perhaps part of an interview.  It’s very basic: you take an integer input, and if that number is evenly divisible by 3, you output “Fizz”, if it is divisible by 5, you output “Buzz”, and if it is divisible by both, you output “Fizz Buzz.”  Nothing to it.  Every professional developer should be able to implement that, and implement it in a few minutes, in several languages – even one that the developer isn’t familiar with.

Why Interviewing Exists

The problem is that there are professional developers out there that will struggle to implement a working solution.  That’s a problem and that’s why technical interviews are the way they are.

I often have to apologize for asking candidates for asking them to implement something simple like Fizz Buzz on the whiteboard, but one of the reasons that interviews exist is to confirm that the candidate is what his or her resume says.  I’ve had more than one candidate walk out of an interview when we turn to the whiteboard.

Please understand that being asked to do some whiteboarding or asking for some code to be written isn’t meant to be some slight to you.  This is the simple nature of interviewing.  Can you get a coding job without writing some code?  Sure, but you are missing out a number of opportunities if you are going to screen out all potential employers that are going to conduct an interview that includes some coding.

What Interviewers Are Looking For

Now, if you get why you are being asked to write some code for a coding job, you may want to know what specifically an interviewer is evaluating you on during that time.  For me, I’m looking at a number of things, but the most important one is understanding the question.

Communication is key in development and the reason we ask for very basic implementations during an interview is that we want to be able to get right to coding without having to describe a complex business problem.  I want you to implement something that you hopefully haven’t done before but is easy to explain.  If we can’t get on the same page as to how a string reverse function should work or the details of the requirements of a method to capitalize all the first letters of a sentence, it’s likely not going to be very easy for us to do so when there are domain specifics that we introduce.

The next thing that I am looking for is fluency in the language.  There are some general factors there, but a lot of that comes down to speed.  It should not take you an hour to implement one of these simple “challenge” type questions.  I recently stumbled across a coding challenge on a popular site that asks to implement a method to uppercase the first letter of every word following a space.  I actually liked that question quite a bit and might mix it into the routine in our interviews.  Here’s my implementation of that method:

using System;
using System.Text;

class MainClass 
{
  public static string LetterCapitalize(string str) 
  {

    var sb = new StringBuilder();
    var cap = true;

    for (var i = 0; i < str.Length; i++)
    {
      if (cap)
      {
        sb.Append(char.ToUpper(str[i]));
      }
      else
      {
        sb.Append(str[i]);
      }
      cap = str[i] == ' ';
    }
    return sb.ToString();
  }

  static void Main() 
  {
    Console.WriteLine(LetterCapitalize(Console.ReadLine())); 
  }
}

 

Why do I like that question?  Well, it hits on a number of things – you have to write a loop, you have to handle some interesting conditional logic, and there are a number of good ways to implement it.  It’s a simple question that I can create some constraints on or ask you to make it better or faster.

The site that I implemented this question on keeps some statistics on questions.  One of which I found to be quite interesting:

The majority of users took almost an hour to solve this problem?  That’s proof enough for me that we have to keep asking “Fizz Buzz” questions in interviews.

Finally, I like to see some good decision making happening.  Sometimes that’s just committing to a brute force solution and getting something on the board.  Other times, it’s choosing to use one type of container over another.  I’ll ask you about why, too, so be prepared to have a good answer.

How to Get Better

Well, it’s a foregone conclusion that you’re going to have to write some code during your next interview.  The best advice that I have for you is to practice.  Chances are that you aren’t going to luck into an interview that asks you to implement something that you’ve already done, but having done a few gets you in the mindset of implementing something on the fly, perhaps without the help of intellisense or the web.

We Actually Don’t Fizz Buzz

We always thought of Fizz Buzz as too elementary to ask our candidates, but sometimes we like to start with something good and add to it.  Think you’ve got what it takes?  Send us your implementation of FibBuzz(n) a method that returns the nth item in the Fibonacci sequence unless that value is evenly divisible by 3, 5, or 15, in which case, return “Fizz”, “Buzz”, or “Fizz Buzz”, respectively.  If we like it, we’ll give you a call!