A question of questions

I have been interviewing candidates for jobs recently. Something I haven’t done for a while but something I quite enjoy doing and also something that I recognise as a skill that you need to keep in practice at if you are going to be any good at it. It has raised some of the old questions about what you should ask candidates in an interview and, if you are interviewing developers, should you get them to write code in the interview.
I once read an article that said that you should always get developers to write code in an interview and used the analogy that if you were recruiting a caterer or chef to cater a function you wouldn’t do it without tasting their food. This is a weak analogy. Firstly, tasting a caterers food is not the same as standing over them and watching while they cook and secondly if you ask to taste their food they will usually turn up with a set of pre-prepared “signature” dishes for you to try. You do not place them in a strange kitchen, hand them a bag of ingredients and ask them to make something on the spot, a la “Ready, Steady Cook”. I have seen job specs recently that stated that “the candidate will be required to pair-program in the interview.” Scary!
For this reason I have occasionally asked candidates to bring some code to the interview with them for us to discuss. Either something they have written that they think is particularly interesting or the output of a simple programming task provided beforehand. This is not always practical though.
However, I will always have a programming related challenge to set them in the interview. I don’t ask them to code as such but rather to chalk-and-talk through the solution in pseudo-code. The point is, I’m not really interested in the seeing the solution in the way I would be interested in tasting the food produced by a chef, I am interested in seeing the approach.
An example of a question I have often used is as follows :
A matrix has been created as a two dimensional (non-jagged) array.
It has been populated with the numbers from 0 to 99.
Figure 1 shows a graphical representation of this matrix. The numbers in red are the index ordinals of each position in the matrix.
Part 1 : Write the code to create and populate this matrix. Keep it as simple as possible.
Part 2 : We want to perform a basic transform on this matrix such that each number in the matrix is transposed i.e. the number at matrix[x,y] should be moved to matrix[y,x] and the number at matrix[y,x] should be moved to matrix[x,y] (see Figure 2).
int n = matrix[x,y];
matrix[x,y] = matrix[y,x];
matrix[y,x] = n;

Write the code to perform this transformation.
Constraints : you may not copy, recreate or repopulate the matrix. You may only use 1 temporary variable (shown as int n in the example above) to store any value from inside the matrix.
What is interesting about this, aside from the variations in answers that I get, is that there does not seem to be any discernible pattern or correlation between the level of skill and experience that a developer claims to have on their CV and their ability to answer this question in an interview.┬áThis got me thinking about this post on Jeff Atwood’s blog from back in February. Am I interviewing a perfectly competent┬ádeveloper who is suffering from terrible interview nerves or can this person really not program ? Have I hit a very specific blind spot or is this representative of a more general inability ? Is there in fact any question or set of questions of which you could say, I absolutely, positively would not hire anyone who cannot answer this ?
%d bloggers like this: