Alternative FizzBuzz-style Interview Questions

Hand drawing chart in whiteboardWhen interviewing programmers, I will usually reserve a portion of the interview for a simple programming exercise.  This is never anything too difficult and is usually conducted on a whiteboard.

I’ve blogged before about the FizzBuzz problem, which is a great little problem to pose to a prospective candidate within the hands-on programming part of an interview.  Of course, it’s possible that some enterprising candidate may well have come across the FizzBuzz problem on the internet and will remember the answer, by route, to the problem without really thinking through the problem and organically realising their own solution.  In and of itself, this isn’t always necessarily such a bad thing, since a candidate that has a familiarity with the FizzBuzz problem is, in my own personal experience, already a step ahead of a lot of other potential candidates, as their familiarity with FizzBuzz shows that they read the kind of blogs and internet pages that care to talk about such things.

Despite this, I often find myself trying to come up with alternatives to the FizzBuzz problem.  This isn’t so easy as it first may sound as there’s a number of distinct properties that the resulting problems must have: 

  • The answer should be short enough to be able to be written in a few lines of code on a whiteboard.
  • The problem must be simple enough to focus one one specific problem area.
  • The problem should allow the candidate to display some aptitude that you care to test for.

Interestingly, I think that a lot of the best FizzBuzz alternatives also make great Code Katas.  A Code Kata is a small exercise that all programmers can perform and practice over and over again in order to improve and hone their skills.  I’ve also found Code Katas to be a great tool to practice Test-Driven Development (TDD), and indeed, many of the FizzBuzz style problems lend themselves very well to TDD derived solutions.

Here’s my list, which is incomplete, but serves to offer a flavour of the alternatives:

  • Reverse a string (without using any built-in reverse functions in your language of choice).
  • Reverse a sentence (i.e. "bob likes dogs" becomes "dogs likes bob").
  • Check if a given string is a palindrome (again, without using any built-in reverse functionality).
  • Find the first location of a string within another string (again, avoiding any built-in language functions to do this).
  • Find the minimum value in a list.
  • Find the maximum value in a list.
  • Calculate a remainder (given a numerator and denominator).
  • Return distinct values from a list including duplicates (i.e. "1 3 5 3 7 3 1 1 5" becomes "1 3 5 7").
  • Return distinct values and their counts (i.e. the list above becomes "1(3) 3(3) 5(2) 7(1)").
  • Check if a given string is a palindrome without using a built-in string.Reverse function.
  • Calculate the factorial of a given number.
  • Calculate the Fibonacci sequence.
  • Given a starting number, count down from that number to 0.
  • Output all multiples of 3 between 1 and 200 in reverse order.

As you can see, many of these are quite trivial to accomplish, much like the original FizzBuzz problem, but there are quite a number of ways in which each simple test can be subtly altered for something similar but different, and which can affect the solution code.  If used in an interview situation, asking a candidate to write a quick solution on a whiteboard to question of "Counting down a number" seems trivial (and is!), but you can easily build upon this by asking for the countdown to be by a specific or arbitrary decrement (i.e. count down by 2 or 3 each time).  Other questions, which are again on the surface fairly simple to answer, are good candidates for a follow up discussion on things like optimization and performance improvements.  For example, the question of checking if a string is a palindrome has various interesting ways in which such a check can be optimized and the check short-circuited.  Finally, all of these questions are great to follow-up with discussions about how the candidates simply code might be altered to ensure testability of the solution via a suit of unit tests.

I’m now a Microsoft Certified Professional!

Microsoft_Certified_ProfessionalFor the past few weeks, I’ve been hard at work studying for my Microsoft Certified Technology Specialist exam (70-573) – Microsoft SharePoint 2010, Application Development.


Well, today, I took the exam and am pleased to report that I passed!


Not only did I achieve the pass rate (which is 70%) but aced the thing and got 100% !  Needless to say, I’m thrilled to bits.


MCTS_logoSince this is my first Microsoft exam, I’m still awaiting emails and communication from Microsoft regarding my MCP ID, Transcript and Certificate (which I’m lead to believe you now have to print out for yourself!) but I do have the Transcript print-out that the Prometric test centre provide immediately after completing the exam.


Looks like I’ll have to dig out a frame for my print-out until I can get my hands on the actual certificate!  Smile


It’s really strange in many ways, as most developers seem to try to acquire certification earlier in their career, primarily to make up for the lack of experience when you’re first starting out.  I’ve done it the other way around.  Despite having nearly 20 years hands-on experience as a software developer, I’m only just now getting an industry recognized certification!


Ah well, better late than never, and I must admit it does feel good.  In many ways, it’s like going back 20-odd years and being back at school again.  The reality, though, is that this is probably my mid-life crisis!  Smile 


I’m not stopping here, though.  The next step is to get my head back into the books in preparation for the follow-up exam, which will give me Microsoft Certified Professional Developer (MCPD) status!  That’s exam 70-576 - Designing and Developing Microsoft SharePoint 2010 Applications.


Onwards and upwards!   Wish me luck!

JavaScript IntelliSense in Razor Views

There’s an issue with getting JavaScript IntelliSense to display in a Razor view of an ASP.NET MVC project.


Turns out that despite having the JavaScript file corrected referenced within your _Layout.cshtml (or some other “global” location) like so:

    <meta charset="utf-8" />
    <link href="@Url.Content("~/Content/Site.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>
    @RenderSection("HeadContent", required: true)


The Visual Studio IDE won’t recognise or parse the:

<script src="@Url.Content("~/Scripts/jquery-1.6.2.min.js")" type="text/javascript"></script>

line when you’re working inside other views within your project.


There’s a hacky workaround for this, though.  You have to reference the JavaScript file from within the view that you’re currently working in.  Although this seems counter-intuitive, and you certainly don’t want a doubly-referenced script as part of your actual solution code, you can place this “dummy” reference in a conditional block of code that will never be reached when your solution is running:

@* Stupid hack to get jQuery intellisense to work in the VS2010 IDE! *@
@if (false)
   <script src="../../Scripts/jquery-1.6.2-vsdoc.js" type="text/javascript"></script>

The if (false) conditional ensures that, when this code is running, the script reference will never be output to the page as the conditional will never evaluate to false (it’ll always evaluate to true).  Despite this, when you’re working in the Visual Studio IDE, the script reference will be parsed and the relevant JavaScript file included (in this case a vsdoc.js file containing the IntelliSense information for jQuery 1.6.2).  This is because the IDE doesn’t care that this script reference code is effectively unreachable, and will happily parse the entire code block anyway!