Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A trivial one is to ask them to code up a breadth-first search of a tree from scratch. Yeah, if you know what you're doing it is trivial. But a lot of programmers don't know how to tackle it.</p> <p>One that I find more useful still is as follows. I've given this in a number of languages, here is a Perl version. First I give them the following code sample:</p> <pre><code># @a and @b are two arrays which are already populated. my @int; OUTER: for my $x (@a) { for my $y (@b) { if ($x eq $y) { push @int, $x; next OUTER; } } } </code></pre> <p>Then I ask them the following questions. I ask them slowly, give people time to think, and am willing to give them nudges:</p> <ol> <li>What is in @int when this code is done?</li> <li>This code is put into production and there is a performance problem that is tracked back to this code. Explain the potential performance problem. (If they are struggling I'll ask how many comparisons it takes if @a and @b each have 100,000 elements. I am <em>not</em> looking for specific terminology, just a back of the envelope estimate.)</li> <li>Without code, suggest to make this faster. (If they propose a direction that is easy to code, I'll ask them to code it. If they think of a solution that will result in @int being changed in any way (eg commonly order), I'll push to see whether they realize that they shouldn't code the fix before checking whether that matters.)</li> </ol> <p>If they come up with a slightly (or very) wrong solution, the following silly data set will find most mistakes you run across:</p> <pre><code>@a = qw( hello world hello goodbye earthlings ); @b = qw( earthlings say hello earthlings ); </code></pre> <p>I'd guess that about 2/3 of candidates fail this question. I have yet to encounter a competent programmer who had trouble with it. I've found that people with good common sense and very little programming background do better on this than average programmers with a few years of experience.</p> <p>I would suggest using these questions as filters. Don't hire someone because they can answer these. But if they can't answer these, then don't hire them.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload