I’m amazed at how many candidates I’ve interviewed cannot provide an elegant solution to the following test:
Write a routine, in your favorite language or even a mock language, without using an intrinsic function to solve the problem for you, to reverse the contents of a string. The routine should take an input of a string and output a string. For example, if the input is “hello” the output should be “olleh”.
I inform the candidate that it is a simple problem and invite them to talk through their logic as they write their solution on the whiteboard. I let them know it does not have to be syntactically correct; I am more interested in their approach.
It is enlightening, to say the least, to watch interviewees attack this problem. I’ve actually had so many people fail that I’ve been questioned if my “test” was too difficult. I understand there are abnormal pressures in play due to the setting but employees should ultimately perform decently under some pressure.
Silently I watch and listen to the candidate attempt to solve the problem. When the candidate is finished I usually ask, with good reason, are you certain this solution is correct? The response is often a “yes.” This usually gives us ample opportunity to talk about different strategies and try to understand why it was coded in a particular method.
I notice lots of issues that should not occur; for example, the candidate:
- does not understand the chosen language or it’s string libraries.
- has issues with zero-based arrays depending on chosen language.
- overly complicates the approach and never sits back to re-evaluate.
- can not come up with a solution.
- chooses a complicated approach involving math and gets the math wrong.
- uses too many variables.
- writes unnecessary code that essentially does nothing.
- can not validate the output of the routine they wrote correctly.
- writes more than ten lines of code to solve the problem.
- does not know how to swap values in to variables properly.
- … and many more.
I’d appreciate others offering this simple test and sharing your results with me and everyone else. I’d also like to know your thoughts the validity of this test and how you would let the results affect your view of the candidate.
Before reading on to see my solution, try it for yourself. Let me know how you do.
(more…)