My Favorite Coding Questions

I was going through the latest posts on Hacker News and Quora tonight and noticed a few ones about coding questions. I really don’t like some of those coding questions, which ask you to “design an algorithm to …”, although those are among many people’s favorites. For example:

Given a string s1 and a string s2, write a snippet to say whether s2 is a rotation of s1 using only one call to strstr routine? (e.g. given s1 = ABCD and s2 = CDAB, return true; given s1 = ABCD and s2 = ACBD, return false)

I know the answer. I heard this problem from my wife when she was preparing for her last job change. I thought hard about it for several minutes and had no clue. Then my wife told me the answer. I was wondering, what’s the point to ask such questions in job interviews to hire programmers. It doesn’t tell me much about what’s the person’s methodology of exploring possible solutions. It doesn’t tell me much about whether this person is a good problem solver — puzzle solver != problem solver. If this person happens to already know the answer (just like I do), this question becomes worthless.

When I do coding interviews for developers, no matter college candidates or industry candidates with several years experience, my favorite questions are those which use very straightforward algorithm. For example,

1. Search a number in a rotated sorted array.
2. Partially revert a linked list.

These kinds of questions help me find out whether the person can translate ideas into code quickly and correctly, which is the most common task in we developers’ daily work. Most of the time, we already know how to solve the problem on the paper, the remaining thing is to just turn it into the code so that computers can execute it (to solve the problem for real). It’s just like that in the restaurants, most cooks’ daily job is to translate recipes into dishes, quickly and correctly. Only occasionally they need to come up with new recipes.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s