Interviewing programmers
One of the very first interview questions I was asked, right after college was:
- Write a function, C or Pascal or whatever language you like, for counting set bits in a an integer.
I’m no fricken genius and thought this was pretty much a softball question. I was asked another simple technical question and eventually I wound up working there for 2 years.
I did think the interview was way too easy, and when I’d grow up and get to interview people, I would start with an easy question like that, but then go from there.
Well, big mistake. Apparently this is a very difficult question for a lot of people. Some of those people are very smart and I want to have them on my team, they can’t see things that small, that’s all. So I had to come up with other starting questions.
Eventually I moved on to “reverse a string”, or “explain hashtables”, or even “code a linked list”.
Recently I interviewed a fellow with some impressive experience. I didn’t want to offend him and start by counting bits so I asked him to code a linked list and write a function for detecting circular linked lists. “In fact” - I said - “don’t even code it, just tell me how you would approach the problem”.
After staring at the white board for 5 minutes, and refusing my help, he finally said “well, there’s no solution to this problem”
I lawled inside of course, and suggested a couple of solutions. His response was “well sure, if you do it that way”.
No, he didn’t make it.
So anyway, some very smart people can’t count bits, others can’t but don’t know what linked lists are. Others can do but their code makes me want to cook (spaghetti, get it?), so what the hell am I supposed to ask as the first question, to at least get us off the ground.
I finally decided on a new approach. I write a bunch of starting questions on the board, and ask them to pick whatever they like best.
If you’re going to interview with me, here are my questions (be ready to pair program with me on the coding questions)
- count 1s in a int. Use this function to figure out if the number is power of two.
- tell me about hash tables. Why they’re needed, how to use them, how to write your own.
- explain linked lists, and write a function for detecting circularity.
- reverse a string
- write an extremely simple calculator class (add/sub/mul/div) but do it test first.
- tell me about your experience with agile (xp, scrum, whatever)
- tell me about object oriented programming. what it is, why I need it, how it works, etc.
- write a function that traverses a tree (breadth first or depth first) and prints the node values
That’s it. Most programmers should be able to pick one and get started. Well, should but don’t. Most programmers I’ve interviewed get stuck at this point.
I’m also considering asking them to come prepared with some source code they think is well written. Not even their code (though that would be better). Just code they read once and found awesome.
I haven’t tried this approach yet though. I do think there’s value there, if you believe that good designers/programmers have taste.
Matt said,
October 23, 2007 @ 12:25 pm
>Just code they read once and found awesome.
If there’s some particular code that they read once and found awesome that says a lot right there. They’re passionate about writing code. If you take their enthusiasm about said code at face value, that is.
I’m not sure how to feel about the count the bits sort of question. Recent grads seem to do consistently terrible with questions like that. My gut tells me that it’s because they’ve gotten incomplete educations, or are just not particularly strong as individuals, but I’m not so sure. When I went to school, bits and bytes were pretty fundamental and were well covered. How can you write tight code, if you didn’t really understand what was happening “on the metal” … right?
In the early 90s, I wrote C and ASM code that used this knowledge, called APIs that used flags encoded as bits, etc.
But I haven’t seen code like that for a long while. Talking to experienced, active developers, they tell me they haven’t either. Eschewing highly efficient storage techniques, such as using bitfields because RAM is cheap seems both a bit wrong but consistent with trends like Vista needing 2G RAM to run well. Higher level constructs may make for easier to read/maintain code, I guess.
So is it not important to teach? Are languages and APIs high-level enough that you don’t need to know it - and therefore it’s a waste to teach in a finite curriculum? I’m not sure.
I am sure that I’d be more comfortable with someone who was so “into” programming that they learned that kind of stuff on their own.
I agree with everything you said, though, and it’s cool to see your techniques evolve.
Interviewing programmers, C++ : Mind Warden | Karel Klíč said,
October 25, 2007 @ 6:36 am
[...] Zajímavý post o testování programátorů pro přijetí do zaměstnání: http://morgane.com/2007/10/23/interviewing-programmers/. [...]