So, my current employer is making it clear my business unit will soon be dissolved. Apparently advertising-based internet operations are à la mode, and having actual paying subscribers to a decent service is passé. So not too long ago I interviewed at Amazon. After two technical phone interviews, I was brought to Seattle for a day of in-person interviews.
Things went generally pretty well, though I didn't get an offer. One of the interview sessions stands out as particularly bad, and I'm sure that had a big impact on their decision.
The interviewer asked me to write a function that would turn a number into words. The upper bounds for the exercise was 100,000,000,000. So, 1,025 should become "one thousand twenty-five". I was told to use any "first tier" language, "C, C++, Java". He agreed that Perl would be fine too.
When I look at this exercise, I see a word problem, not a number problem. Divide the number up into three character chunks (with a possible element less than three characters) and turn that into words. It's basically "commify" with a twist.
So, I set about writing a little code on the whiteboard. First, I reversed the string (the number) and started iterating over it pulling out chunks with a substr(). My goal was to get the three char chunks into an array. I know there are better ways to do this, but under stress I took the route I thought of first.
I was stopped by the interviewer almost immediately and was asked why I was treating the number as a string. For a moment the question didn't even make sense to me. Had I been thinking clearly and not been confused, I might have asked him why it shouldn't be treated as a string. Mostly I just stammered and blew the rest of the interview.
The solution he was looking for used "% 1000" to get the chunk followed by "/ 1000" to set the number up for the next call to the modulus. It's possible I would never have gotten to that solution without prodding from the interviewer.
The whole experience was humbling, but not terrible. I learned a bit about Huffman coding from another interviewer and implementing database-based linked lists from another.
I also got really good insight into some interviewing techniques that maybe I'll be able to use sometime.