Simple Questions, Revealing Answers
I’ve given some job interviews. Using what I’ve learned from job interviews I’ve gotten, especially the distasteful rote Q&A so common in the job market, I’ve crafted two simple bits that quickly show the kind of job candidate I’m talking to:
- Tell me about a creative solution you devised and are proud of.
- Tell me about a problem that defeated you.
The first question shows what kind of thinking a person has. The second shows how honest the person is.
The first time I used those questions, I had two job candidates to interview. The first candidate answered both questions reasonably candidly (without violating her previous NDA’s). The second candidate tried to tell me that, in six years of professional programming, he had never encountered a problem that defeated him. Either he lied, or his experience was based on such simplistic situations that he was unqualified anyway. Based on that one response, I rated him negatively on the interview.
We hired the first candidate, who immediately began challenging assumptions and streamlining the user interface.
My very first programming job challenged me to create a solution that I’m still proud of. I needed to maintain two indices for a customer appointment system: index by name, and index by customer number. I had to support insertion, retrieval, deletion, and save, but all internal structures were up to me to devise. The indices would load when the program started, and all modifications required an immediate save-to-disk for persistence.
I had no problem with saving, loading, deleting, and lookup. Actually, the saving and loading were the simplest parts of the library, with simple write-from-memory and read-to-memory calls. However, the insertion turned into more of a problem than it should have been.
The standard C library includes a function called qsort() which is supposed to implement C. A. R. Hoare’s Quicksort algorithm. One of its parameters is a pointer to a function to do the actual comparison of two elements. The function can return -1, 0, or 1 to indicate that the first element is greater, they are equal, or the second element is greater. (Or you can reverse the 1 and -1 to get a reversed sort.)
Despite my best efforts, and some of the best hacking I’ve ever done, I was unable to get qsort() to work for me. In order to get the job finished on time, it became obvious I would have to make my own sort function.
I initially tried to re-implement the Quicksort, but gave it up as too complicated for the task at hand. I considered the bubble sort but even it wasn’t appropriate for what I needed. I had an almost-sorted list, with just one out-of-place element in the last position. What did I need?
In retrospect, it almost seems silly, but I spent almost two hours pondering this. When normal thinking failed me, I decided to think “backwards”: what would get me from a sorted list to what I had to contend with? Well, I only needed to move the one item out of place…
Of course! I merely had to swap the new item with the one before it, until it was between the two elements which were less than and greater than itself!
No full-blown sort needed, no need to examine every single element of the list, no need to consult with some programming text on standard sorting algorithms. It was a particular solution to a particular problem, and when my customer put the code in place, it worked beautifully.
To this day, I am pleased with myself for having come up with such a functional solution on my own. It was one of the first times I managed to “think outside the box,” and it remains the standard against which I measure my own creative thinking.