Adventures in post-college life

A favourite interview question

Today I interviewed a candidate for an internship on my team. One thing I’ve learned from when I conducted screening interviews for potential Extreme Blue candidates at IBM was that no matter how well a candidate answers theory questions, you still don’t know if they code. As an interview, you must ask the candidate to write some code. Given that it’s an interview, and the candidate is sure to be nervous as hell, I picked a simple question:

Write a function (in Java) that takes as arguments a string and a char, and returns the last index of the specified character in the string.

It sounds simple enough, but believe me I’ve seen more than my fair share of failures and embarrassments on this question. It’s like FizzBuzz.

Some of the things I look for in an answer:

  1. Did the candidate ask what to do if the character isn’t found in the string at all? (In which case I tell him to return -1, but I don’t volunteer this information until he asks).
  2. Did he search the string from the end instead of from the beginning?
  3. Does he handle the case of a null or empty string?
  4. Is his code clear and easy to read?

I’m always surprised at how many times one, two or all of those criteria are missed.

Creative Commons License
Geekflex by Eitan "Skrud" Levi is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 Canada License.
The views and opinions expressed on this site are my own, and in no way represent those of my colleagues, employer, or anyone else.
Hosted by Site5