Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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
share|improve this question
19  
If I was given that question I'd have to say: "Is a knowledge of complex numbers a requirement for this position? because In 14 years as a professional programmer I've never needed to utilize them. Would you please give me a quick overview?" Depending on your response, I'd then immediately know if it was worth continuing the interview. – Ash Jun 14 '10 at 12:23
2  
@djhworld - I want to see if they can take a not-so-well defined question (what is "for all natural n" in a computer anyways?) and translate it to a programming question. There are quite a few questions I expect the candidate to raise here, which would be a good sign. But going from a domain-specific question to a programming question is part of the deal here. – Gilad Naor Jun 14 '10 at 12:40
2  
Stefan: "expresso"? – Ken Jun 14 '10 at 17:19
3  
"For all c between (-2, i) to (2, i)"... this is an uncountably infinite domain. What, exactly, are you asking for? Are you sure you didn't mean "c is a Gaussian integer"? – Derrick Turk Jun 14 '10 at 17:26
2  
Scary? Looks like FizzBuzz... :-/ – Andrea Dec 22 '11 at 9:13
show 14 more comments

migrated from stackoverflow.com Dec 22 '11 at 8:23

10 Answers

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.

share|improve this answer
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 Jun 14 '10 at 11:13

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.

share|improve this answer
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 Jun 14 '10 at 13:23
@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 Jun 14 '10 at 13:37
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 Jun 15 '10 at 10:57

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.

share|improve this answer
This sounds nice as a first question, which can then be expanded to something with more "weight". – Gilad Naor Jun 14 '10 at 13:22
I disagree. File I/O is something some developers never do. This is the kind of stuff you look up from an API reference. – Otto Harju Dec 22 '11 at 17:42

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

share|improve this answer

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.

share|improve this answer
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 Jun 14 '10 at 11:39

Why not give them some problem they'd actually face while on the job? One of the few times I was given a test like this, the problem was to describe what a piece of code did and find the bug in it. The code was something they had pulled from their actual codebase and the bug was non-trivial but pretty easy to spot if you knew what to look for (in one case a character string might not be null-terminated, IIRC). Once that part was over, it led naturally into a discussion of what they were doing and the kind of problems they were working on.

share|improve this answer

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 :

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

share|improve this answer

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

share|improve this answer
This does not provide an answer to the question. To critique or request clarification from an author, leave a comment below their post. – World Engineer Oct 15 '12 at 20:38

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.

share|improve this answer
Was the catch that the arrays were sorted, and you could've used binary search? – Otto Harju Dec 22 '11 at 19:29
hi @Otto. Binary search would definitely improve it but I think I had adjusted the arrays to map directly the chars and avoid loops. – Nick Dandoulakis Dec 22 '11 at 21:53
oh I see now, code page is just another name for character encoding. I guess checking the bounds of 'ch' and then adding a constant did the trick, if the mappings are so simple for every single character (that is, the character order remains the same from one code page to another). – Otto Harju Dec 23 '11 at 12:10

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.