In a previous blog entry I had talked about an instance where I failed an interview for the first time, in the very first round, no less. That was when I was a newbie and so I can rationalize it away as sort of understandable. Fast forward about 25 years and brimming with overconfidence I managed to flunk an interview - again at the very first round - this one over a trivial coding problem.
This interview was at a startup and I was told I would go through a screening round just like all the other candidates. Remember that I had over 25 years of coding under my belt at this point, at least 10 years of which was debugging and fixing various bugs in the Solaris kernel. The recruiter told me that this was their standard operating procedure and assured me that it was just a simple screening phone call with an shared online coderpad used for a "light" coding exercise.
With not enough sleep from the previous night, I loaded up on coffee and linked up to the coderpad screen while on the phone with the interviewer (who sounded like a kid fresh out of college). After the usual preliminaries, he got down to brass tacks and said: "implement atoi".
In retrospect and as a quick test for myself, I tried it just now and got the following code working in slightly under 4 minutes (3 minutes 22 seconds to be very exact).
#include <stdio.h> // printf
int
main(int argc, char **argv) {
char c, *p=argv[1];
int n=0;
while (c=*p++) {
n *= 10;
n += (c - '0');
}
printf("%d\n", n);
}
The only bug I had in coding this was not initializing 'n' (initially) and I was able to trivially fix it without even thinking about it too much. But in the actual interview environment, this was not what happened at all. Not by a long shot. No sir!
When I was faced with this question, my first instinct was to reach for a recursive solution (to impress the interviewer? I don't remember anymore now). And for some reason, I decided I needed to reverse the string. All in all, I was coding without really thinking, what with all the adrenaline and caffeine coursing through my blood stream.
Long story short, I took about 3 rewrites and 30 minutes to finally get a working version. Feeling frazzled and sweaty, I was not prepared for the interviewer's next question: "What changes to the API of atoi would you make?" Unlike the code I showed earlier, this was coded as a standalone function.
Tired of the entire exercise, I said I'd keep it the way it was. Din, din, din, din, din ... wrong answer!
Even over the phone I could feel the interviewer retreat into his shell and try to wind up the call as soon as possible after the routine/cursory "Do you have any questions for me". I said I had none.
So that was it, I never heard from the recruiter or that small startup again. I assume I must have got on their "do not rehire"/DNR list - even before I could get past their preliminary coding round. A couple of weeks after that (and after brushing up on my l33tcode), I was luckily hired by Amazon.
It is over 5 years since this happened and to this day I can't understand how I could dig myself into a hole like that over a trivial coding exercise. Maybe on some interview days you should just dial down on the coffee (or something).