Guus Bosman

software engineering director


You are here

Work NC

A great, quick interview question

One of the most difficult decisions I make in my job is deciding on hiring a candidate. Make the decision well, and the team will grow with a productive team member and everybody's happy. Make a bad decision, and I'm in for a potentially long, difficult and distracting track.

There are many things I look for in a candidate, but for software engineers programming skills are obviously key. Over the years I've had good luck and bad luck when hiring new people, but I quickly learned that doing a good job interview is a lot harder than it looks. Now, years later, I feel competent, but finding a good candidate still requires a lot of attention and energy.

I always incorporate a little bit of coding during interviews, even during the phone interview. No matter how senior the job and no matter how many years of experience a candidate has, I'll always do it. It's amazing how a simple programming assignment can give you insight in how people think and write code. It's even more amazing that lots of candidates don't even pass a basic coding question. One of my favorite questions is this:

Given an array of integers, write a method that will return the largest number (the maximum value) in the array. The integers are: 4, 6, 2, 4, 11, 5, 3.

Yes, this is a real simple question, and yes, it has a real simple solution. I always make sure I carefully explain the problem, clearly state the assignment and ask the candidate if they understand my question. They can code it in Java or C or in the rare case that they know neither any other language. And yet, lots of them fail!

Clearly, this is only a first check. Beyond the first phone conversation and the simple coding questions there's a whole layer of other questions and coding assignments, but as a quick screening tool questions like this are hard to beat. If you're interviewing for technical positions, I strongly recommend you always incorporate such a quick test for basic coding skills.

Interviewing is hard, and it's an art I'm always working to improve. A book that helped me early on, and gave me a better understanding of the theoretical and practical aspects of interviewing is Hiring the Best by Martin Yate. I still occasionally re-read parts of it and I highly recommend it to anyone who wants to improve his or her recruiting and interviewing skills.

(If you're in the market right now and are interviewing at my company soon: bonus points for reading my blog and mentioning it during the interview. Another thing I look for in a candidate is a genuine interest in the company and team that you may work with for the next years of your life).

Comments

Thats weird, why would you apply for such a job when you cannot even solve that!
(i still remember the first time i was told about arrays, by you! :))

greets

Wow, that is a long time ago, talking about arrays :) We're getting old! ;)

While there are candidates who have no idea how to solve it, most them do have some sort of idea but aren't able to write a working solution (they'd mess up a variable, 'forget' how to do a loop over an array, that sort of thing).

Hmmm,

What kind of degree does such candidate have? (I have some doubts about my english grammar..:)

grtz Gerben

If have a possible solution....

#include <iostream.h>
#include <conio.h>

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

/*
   Function	: GetMaximumValue()
   Description : returns the maximum value found in a given array
   input	    : arrayIndex: current index to read from array
				  arraySize : size of the array
   result      : highest value found in the array
*/
int GetMaximumValue(int arrayPos, int arraySize)
{
   int result = 0;

   //Check if end array is reached
   if (arrayPos < arraySize)
   {
	 //return the highest value currently found in the array
	 return result = array[arrayPos] < (result = GetMaximumValue( (arrayPos+1), arraySize)) ? result : array[arrayPos];
   }
   return 0;	
}

int main (void)
{	
   char buffer[256] = {0};

   //Copy output in buffer
   _snprintf(buffer,sizeof(buffer),"Maximum value is: %d\n\rPress a key to exit..", GetMaximumValue(0,SIZE_OF_ARRAY(array)));  
   //print buffer on screen
   _cputs( buffer );
   //wait for user to end program
   getch();
}

I must admit, a for loop is a less difficult way :) and I could use a if statement to get right return value in GetMaximumValue().

Sorry for the outlining

grtz Gerben

Nice, a C++ solution!

Like you said, a loop would have been easier but obviously this recursive algorithm will get the job done.

I think I nailed it:

/*
* Returns the maximum value of an array containing
* the numbers 4, 6, 2, 4, 11, 5, 3
*
*/
public int getMaximum() {
       return 11;
}

Cheers,

Joris
(Who has no idea what is username/pwd is, if he even has one anymore)

Joris, thanks for your response. Your code is well documented and uses a clear method name.

You could have scored extra points by using a constant (MAXIMUM_INTEGER) instead of 11 as a hard-coded value but I'm impressed by your sophisticated algorithm. Good job!

I wonder if my son knows this kind of stuff yet, I'll ask him.

Just over a year ago I was asked to do some easy XSLT transformation during a job interview. No problem, but the simple assignment (and above all: the enthusiasm about my solution) did make me wonder if the job would actually be interesting. Well, I should not have doubted my gut feeling, as the job indeed did not meet my expectations. Next time I get a question like that I'd really doubt if I want to work with that company...

By the way, I think Joris' answer is 31 off. And you should have rejected Gerben's solution -- what about arrays with all negative values, my dear Guus? ;-)

I read your comment in the morning.

Only when I was doing the dishes after dinner it dawned on me what you meant with "Joris' answer is 31 off"...

...I'm not sure if "31 off" is correct English, but I hope I don't need to explain the problem with all negative values ;-)

Recent comments

Recently read

Books I've recently read: