views:

366

answers:

9

Spent some time searching, couldn't find exactly what I'm after.

We like giving hands-on programming exercises as part of the interview process. The interviewee gets a laptop, with the editor and compiler of his choice. He or she then get a programming exercise and has about an hour to code it. Depending on the nature of the question, internet access is either allowed or forbidden.

I'm looking for good general questions for a junior developer. I don't care what language they choose to program in. C++ is as good as Python or Scheme, as long as (s)he can program in it (this rules out "can you write a correct copy-constructor" style questions). I just want to see how they code, if their code is self-documenting, if they write tests, check edge-cases, etc.

What kind of questions would you ask?


edit: The questions should be simple. I'd probably go with a question I can solve well in no more than 20 minutes. However, this is not the first stage in the interview process, and I can assume the person in front of me knows how to program.

Example question:

c is a complex number.
Z(n+1) = Z(n)^2 + c
Z0 = 0
c belongs to the set M iff |Z(n)| < 2 for all natural n

For all c between (-2, -i) to (2, i), print:
'X' if c is in M
'.' otherwise

This looks like a scary mathematical problem, but it's actually very easy, and can be coded in under 10 minutes. Once you get the correct answer, it is visually obvious that you have the correct solution

edit: If the candidate doesn't remember his complex numbers, I show them everything they need about it. I want to see if they can look at a scary problem, and know which questions to ask. For example, you have to use SOME_BIG_NUMBER in the partial solution below

def isInSet( c ):
    z_n = complex(0, 0)
    for i in range(1, SOME_BIG_NUMBER):
        z_n = z_n**2 + c
        if abs(z_n) > 2:
            return False

    return True
+4  A: 

As difficult as this is to believe, you can make the desired test program pretty damned simple and still have most of your prospects fail the test. Even something as simple as the "FizzBuzz" thing can weed out an astonishing number of "programmers" who can't code.

Yes, it really is that bad out there.

JUST MY correct OPINION
Yes, I'm sadly aware of this fact. However, so far we've been pretty good at weeding these out before the interview, so I'm after something more difficult than FizzBuzz. Not too complicated, though, because they only have an hour (code+documentation+tests, if they're good)
Gilad Naor
+1  A: 

If you want to give programming questions then there are lot of online judges loaded with tons of questions. You can select some questions from there and morph them or modify them slightly. you can have various questions with varying difficulty level too as your interview level go up.

Some online judges are :

Topcoder, UVA online judge, Codechef, SPOJ Online, Project Euler, Ural OJ (http://acm.timus.ru), Saratov OJ (http://acm.sgu.ru), ZJU OJ (http://acm.zju.edu.cn), Official ACM Live Archive (http://cii-judge.baylor.edu/), Peking University Online Judge (http://acm.pku.edu.cn/JudgeOnline/), Programming Challenges (http://www.programming-challenges.com)

You will get very good questions on programming, data structure, algorithms and maths.

Sorry for Bad formating, Rich text editor is not working for me in Mozilla Firefox.

GG
+1  A: 

Try something like a simple hangman game, or a "higher or lower" guessing game.

Vicky
+2  A: 

Definitly something that would require to use recursion.

Also, implementing some very basic data structures (like stack or queue) may be a good idea.

Another thing that comes to mind is some simple task that requires reading documentation on some API and using it.

Or maybe something like giving description of an algorithm and asking to implement it. For example heapsort.

zifot
Giving them some existing code which they then have to utilize or expand is a nice idea.Alas, it would force the candidate to use a specific language, or know how to talk to a dll/so...
Gilad Naor
@Gilad Noar: You can always use some simple scripting language or even pseudo code - after all it's not about it actually working but rather about ability to recognize API's entry points and how to use them based on docs.
zifot
Yes, but for this I can give them printouts. I want to take advantage of the added benefit of actually giving them a computer and a hands-on exercise.
Gilad Naor
+1  A: 

In a recent recruiting process I've been involved with, less than 20% of the candidates could write a factorial() function (we required that they write both a recursive and a non-recursive version). I think this is a really low bar, so you can start with this and then increase the difficulty of the test.

Humberto
Fibonnaci is also a nice question. You can see if they can nail the complexity, and how to improve it (i.e. memoization). The good ones will say you can solve it in O(1).But I don't see much added benefit to letting them actually program it. You can understand just as much about them using a whiteboard.
Gilad Naor
A: 

You can also maybe make some question regarding the understanding of reference-semantics.

Pedro Morte Rolo
A: 

IIRC, I was given a function like the one below and I had to improve it.

/* C language. The actual arrays were bigger */
char mapping(char ch)
{
    static char *arr1 = "ABCDEF";
    static char arr2[6] = {128, 129, 130, 131, 132, 133};
    BOOL found = FALSE;

    for (int i = 0; i < 6; i++)
        if (ch == *(arr1+i)) {
            found = TRUE;
            break;
        }
    return found? arr2[i] : ch;
}

The real function was doing character mapping between two different code pages.

Nick D
+2  A: 

Open a file and print it out to the console.

A friends' company used to do this and most people fail the test. I think it's a great weed out question, you're either competent and it takes 3-5 minutes (accounting for nervousness here), or you're incompetent and you'll never get it done.

This is very fair if the interviewee gets to do this in a language of his choice, and it's not some weird contrived puzzle.

Mitch Haile
This sounds nice as a first question, which can then be expanded to something with more "weight".
Gilad Naor
A: 

I had this as a recent programming example:

Generate a list of integers from 1 to 10,000 with each value appearing in the list once in a random order.

Now, this is really simple and vague, but that may well be part of the exercise, figuring out how to overcome the various shortcomings as someone could build a console application, winforms application, web page, web service or possibly something else that does this but the idea is to have something that should be simple and straightforward and see where they go with it.

JB King