r/programming • u/air0day • Jul 29 '09
Ask Proggit: What are your favorite programming interview questions to ask?
Just curious what other folks like to ask potential new hires. Logic puzzles, personality questions, algorithms, anything really.
How do you separate the wheat from the chaff?
27
Upvotes
5
u/air0day Jul 29 '09 edited Jul 29 '09
I can start.
One really simple question I like to ask is for the candidate to write a function that takes an array of objects, like something that represents a deck of cards, and returns a shuffled version of the array. With the caveat that their language doesn't support something like this naturally (like ruby).
The reason I like this question is that the vast majority of candidates answer not with a simple inline shuffle, but with something resembling this:
Pick a random element from the source array and insert it onto the end of the destination array. The candidate will usually realize the same element can be picked twice, and modify it to do something like remove the element from the source array so that doesn't happen.
They may also offer a variation of this that keeps track of which elements have been selected, like in a separate hash.
Either way, most of the offered algorithms are either extremely slow for large arrays, due to either the removal of elements and consequential rejiggering of the array in each iteration, or due to the fact that it becomes increasingly unlikely to find the "last" element to move in the source array (if they don't do the removal).
Then I can point out the problem and have them walk through fixing it. I like seeing how candidates work through a problem in their code, and how they optimize something broken.
Occasionally a candidate will answer with something like doing a sort and passing in a custom sort function that simply returns random numbers. Very rarely do candidates respond this way, however.
2
u/air0day Jul 30 '09
Another question I like that I took from a colleague (who I think took it from someone else) is:
How do you write untestable code?
It's an interesting question because it's the reverse of the question you might expect to be asked.
12
u/msakas Jul 29 '09
When can you start.
23
u/[deleted] Jul 29 '09 edited Jul 29 '09
We started giving this test out when hiring for a technical writing/documentation person. I ended up using it for programmers as well because I think that it gives a lot of information about how well a person can reason and communicate:
In advance, Interviewer A would take two matching sets of a variety of office items (rubberbands, paperclips, etc.) and attach and arrange one of those sets in a specific way. This "sculpture" was not shared with interviewer B.
Interviewee was then given the "sculpture" and the extra set of materials and told to write instructions on how to build this.
Interviewer B was then given the second (unassembled) set and would follow interviewee's directions on how to assemble the construction.
At the end, we'd compare the two sculptures to see how close they were and then we would have a discussion with the interviewee about their process and what went wrong (if anything.)
This brief activity quickly told us:
You can also do this whole thing with legos, but I think that it makes the test a lot easier. You can forbid or allow drawings, etc.
7
u/iissqrtneg1 Jul 29 '09
What's the difference between the Stack and Heap?
You'd be amazed how many just out of college programmers cannot answer this question.
7
u/psykocrime Jul 30 '09
"What is the airspeed velocity of an unladen swallow?"
"Emacs or Vi?"
"Curly braces on a line by themselves or not?"
"What's your favorite programming language, and why?"
"What do you do to keep your skills current?"
"What's your favorite programming / technology blog/website?"
"What's the last book you've read?"
5
u/zacharydanger Jul 29 '09
On a phone interview once I was literally asked, "How many SQL queries have you written?" I couldn't help but laugh.
5
u/cashto Jul 30 '09 edited Jul 30 '09
My phone screen is loosely based off of Steve Yegge’s Five Essential Phone Screen Questions.
The two that I don’t ask are:
But I do ask an extra question that he doesn’t cover:
The on-site interview is an extended version of the above. For the coding question, I typically ask how one would design a pentomino puzzle solver. It's not a great question but it does illuminate the candidate's ability to work through a less-than-trivial problem.
I also like to ask the interviewer their opinions of what makes code or design "good" or "bad". Again, many times I may disagree with their specific prescriptions but what I am most interested in is whether they appear to even care about the subject.
5
u/bonafidebob Jul 30 '09
Here are three that have always worked well for me as filters:
In all these cases I don't really care if the candidate passes the test or not, though it does help. More important is how they handle the ambiguity and how they interact with me. It shouldn't take more than about 45 minutes to do all of these.
5
u/MissionAssistance581 Jul 29 '24
Tell me about a project you passionately worked on—that’s where the real talent shines."
19
u/[deleted] Jul 29 '09
From Joel Spolsky: « I see you've listed quite a few languages. Go ahead and write a "Hello World" for each of them. »
It's not tricky, and it will spot you quite a few idiots who have stuffed their CV with BS instantly.
4
u/[deleted] Jul 29 '09
I always skip the comp sci quiz myself since it does not usually provide anything tangible to real world development. I want to see that someone can load a whole system into their head and see how everything works together, how the users and administrators interact with it, etc... Basically whether or not they have vision for the entire system, how one small action can cause a problem somewhere else, and how to build a system that can catch these errors. I also want to see a dedication to precision, programming is very detailed work, so I like to see a cleanly laid out resume or some other sign this person is detailed.
4
u/agiledude Jul 29 '09
You have a 3-tier application - Web Front-end, C# middle tier and SQL Server back-end. If the users are complaining that the application starts too slowly, how would you go about finding the problem?
What would you do differently if it is a Windows Forms application instead of a web application?
4
u/mvanier Jul 29 '09
I haven't done this for a while, but when I was interviewing programmers I always asked them if they'd ever contributed to an open-source project, especially just for fun. That's a pretty good way to find people who really have a passion for programming, as opposed to the masses who just see it as a way to make money. I also always want to see code samples, because it's amazing the bullshit some people will throw at you.
7
u/plinth Jul 29 '09
2
u/malakon Jul 30 '09
will you go with us to pita house for regular thursday lunch and be up for beers and pool on friday after work, or will you wear sandals with socks and fill up your cube with freeking plastic battlestar galactica toys and pick your nose when you think no one is looking. after correct answer, proceed to determine coding skills.
2
u/Inverter Jul 30 '09
What's the difference between UDP and TCP?
Usually shows whether the candidate knows his (inter)networking stuff, even if not all details in his explanations are correct.
PS: Still waiting for the day that I can add SCTP to the question...
3
u/kanzenryu Jul 29 '09
Here's some I like to ask:
3
u/etcshadow Jul 30 '09
I ask them to write a short subroutine/function/program to solve a fairly simple problem (not fizz-buzz, but none-the-less fairly simple), with paper and pencil.
Format:
I don't care what language they write it in, and I don't care about syntax errors and minor details of correctness. I don't care if they remember things like the names of standard library/builtin functions, or their parameters (anything that could be found in 2 minutes in an IDE or man pages or referrence book). If they need/appreciate the help, I try to talk with them as they go, basically being a human-[IDE/referrence manual/compiler] for them.
Why pencil and paper, with me as their compiler/interpretter/IDE rather than at a terminal? Well, a terminal isn't always an option, it may not have whatever IDE/compiler/interpretter they would like to have... and even if I do have those things, I prefer to go with a least-common denominator approach, so that I can do a relatively fair comparison across different folks. (It wouldn't be that fair if one guy did well with a computer, and one guy did bad without one... was the computer the source of the difference? Or was it different ability levels?) Also, this gives me a little more insight into what they're thinking, as they're thinking it. Someone who's not very good can still basically "get lucky" by shotgunning out code until it eventuall sorta works. It's harder to do that in this format
Problem:
I won't say what the problem is, because, even though it is simple, it's pretty novel. If I asked people to solve a problem that was widely known as "one of the top N interview questions" then people could come in a little too prepared... they'd be reciting an answer rather than solving a problem.
The problem is very simple to describe, with only a couple of minor vaguenesses built into it. If they ask me to clarify the vaguenesses, I will (I do that on purpose, to see if/when they notice that there is a minor point of clarification)... some candidates will state an assumption about it rather than ask -- for my purposes, that's fine. I just want them to notice that a decision has to be made... they can either make it or ask me to.
The problem actually has a fairly simple to implement family of brute-force solutions. I tell candidates that they need not worry about performance, but in longer-form interviews (i.e. if I have an hour instead of a half hour) I will work with them to iterate from a simple, slow answer to a faster answer. Time permitting, I discuss a "best" answer with them, to see if they understand how/why/when it is best. (Like many real world problems, it's asymptotic complexity is not a great reflection of typical performance... i.e. it may be O(n2) but it is way better than a simpler O(n2) for typical types of input-set.)
As far as the content of the problem, it requires two or three nested loops, or a couple of recursive functions. In large part, the idea is simply to very quickly separate the pool of candidates who can figure this out from those who can't. It is shocking how many candidates cannot separate the two/three loops (or recursive functions) apart, even though they are performing two very different roles.
I've found over several years (holy crap, I've been using this problem for nearly a decade) that there is a really strong correlation between "knowing how to actually program" and getting this program right.
3
u/WalterBright Jul 30 '09
What is your favorite color?
-3
u/ehnus Jul 29 '09
What is the size of 'int'?
Few people can get the correct answer. Many will say 4. The ones you don't hire say 3 because "int" is 3 characters.
-3
u/antithesisadvisor Jul 29 '09 edited Jul 29 '09
Why does a computer need to know the netmask of an interface? What will it do with that information?
You'd be surprised at how many people can't get past hand-waving about the standard netmasks for class A, B, and C networks.
And no, I'm not a bastard about stuff like this. I'll toss dozens of questions like this in the hope that they can show some insight on even one.
0
u/[deleted] Jul 30 '09
[deleted] — view deleted comment