<p>What are some simple algorithm or data structure related "white boarding" problems that you find effective during the candidate screening process?</p>

<p>I have some simple ones that I use to validate problem solving skills and that can be simply expressed but have some opportunity for the application of some heuristics.</p>

<p>One of the basics that I use for junior developers is:</p>

<blockquote>
  <p>Write a C# method that takes a string which contains a set of words (a sentence) and rotates those words X number of places to the right.  When a word in the last position of the sentence is rotated it should show up at the front of the resulting string.</p>
</blockquote>

<p>When a candidate answers this question I look to see that they available .NET data structures and methods (string.Join, string.Split, List, etc...) to solve the problem.  I also look for them to identify special cases for optimization.  Like the number of times that the words need to be rotated isn't really X it's X % number of words.</p>

<p>What are some of the white board problems that you use to interview a candidate and what are some of the things you look for in an answer (do not need to post the actual answer).</p>

[{'answer_id': 58356, 'author': 'DevelopingChris', 'author_id': 1220, 'author_profile': 'https://Stackoverflow.com/users/1220', 'pm_score': 3, 'selected': False, 'text': '<ol>\n<li>Write a method that takes a string, and returns true if that string is a number.(anything with regex as the most effective answer for an interview)</li>\n<li>Please write an abstract factory method, that doesn\'t contain a switch and returns types with the base type of "X". (Looking for patterns, looking for reflection, looking for them to not side step and use an if else if)</li>\n<li>Please split the string "every;thing|;|else|;|in|;|he;re" by the token "|;|".(multi character tokens are not allowed at least in .net, so looking for creativity, the best solution is a total hack)</li>\n</ol>\n'}, {'answer_id': 58358, 'author': 'David Citron', 'author_id': 5309, 'author_profile': 'https://Stackoverflow.com/users/5309', 'pm_score': 5, 'selected': False, 'text': '<p>I enjoy the classic "what\'s the difference between a LinkedList and an ArrayList (or between a linked list and an array/vector) and why would you choose one or the other?"</p>\n\n<p>The kind of answer I hope for is one that includes discussion of:</p>\n\n<ul>\n<li>insertion performance</li>\n<li>iteration performance</li>\n<li>memory allocation/reallocation impact</li>\n<li>impact of removing elements from the beginning/middle/end</li>\n<li>how knowing (or not knowing) the maximum size of the list can affect the decision</li>\n</ul>\n'}, {'answer_id': 58366, 'author': 'Jim Puls', 'author_id': 6010, 'author_profile': 'https://Stackoverflow.com/users/6010', 'pm_score': 5, 'selected': False, 'text': '<p>Once when I was interviewing for Microsoft in college, the guy asked me how to detect a cycle in a linked list.</p>\n\n<p>Having discussed in class the prior week the optimal solution to the problem, I started to tell him.</p>\n\n<p>He told me, "No, no, everybody gives me that solution. Give me a different one."</p>\n\n<p>I argued that my solution was optimal. He said, "I know it\'s optimal. Give me a sub-optimal one."</p>\n\n<p>At the same time, it\'s a pretty good problem.</p>\n'}, {'answer_id': 58405, 'author': 'dotmad', 'author_id': 6060, 'author_profile': 'https://Stackoverflow.com/users/6060', 'pm_score': 2, 'selected': False, 'text': '<p>I like to go over a code the person actually wrote and have them explain it to me.</p>\n'}, {'answer_id': 58812, 'author': 'Bill the Lizard', 'author_id': 1288, 'author_profile': 'https://Stackoverflow.com/users/1288', 'pm_score': 4, 'selected': False, 'text': '<p>When interviewing recently, I was often asked to implement a data structure, usually LinkedList or HashMap.  Both of these are easy enough to be doable in a short time, and difficult enough to eliminate the clueless.</p>\n'}, {'answer_id': 58983, 'author': 'Jon Dewees', 'author_id': 1365, 'author_profile': 'https://Stackoverflow.com/users/1365', 'pm_score': 3, 'selected': False, 'text': '<p>Follow up any question like this with: "How could you improve this code so the developer who maintains it can figure out how it works easily?"</p>\n'}, {'answer_id': 63512, 'author': 'Aaron N. Tubbs', 'author_id': 4810, 'author_profile': 'https://Stackoverflow.com/users/4810', 'pm_score': 3, 'selected': False, 'text': '<p>Graphs are tough, because most non-trivial graph problems tend to require a decent amount of actual code to implement, if more than a sketch of an algorithm is required. A lot of it tends to come down to whether or not the candidate knows the shortest path and graph traversal algorithms, is familiar with cycle types and detection, and whether they know the complexity bounds. I think a lot of questions about this stuff comes down to trivia more than on the spot creative thinking ability.</p>\n\n<p>I think problems related to trees tend to cover most of the difficulties of graph questions, but without as much code complexity.</p>\n\n<p>I like the Project Euler problem that asks to find the most expensive path down a tree (16/67); common ancestor is a good warm up, but a lot of people have seen it. Asking somebody to design a tree class, perform traversals, and then figure out from which traversals they could rebuild a tree also gives some insight into data structure and algorithm implementation. The Stern-Brocot programming challenge is also interesting and quick to develop on a board (<a href="http://online-judge.uva.es/p/v100/10077.html" rel="noreferrer">http://online-judge.uva.es/p/v100/10077.html</a>).</p>\n'}, {'answer_id': 90047, 'author': 'user11318', 'author_id': 11318, 'author_profile': 'https://Stackoverflow.com/users/11318', 'pm_score': 2, 'selected': False, 'text': "<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>\n\n<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>\n\n<pre><code># @a and @b are two arrays which are already populated.\nmy @int;\nOUTER: for my $x (@a) {\n  for my $y (@b) {\n    if ($x eq $y) {\n      push @int, $x;\n      next OUTER;\n    }\n  }\n}\n</code></pre>\n\n<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>\n\n<ol>\n<li>What is in @int when this code is done?</li>\n<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>\n<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>\n</ol>\n\n<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>\n\n<pre><code>@a = qw(\n  hello\n  world\n  hello\n  goodbye\n  earthlings\n);\n@b = qw(\n  earthlings\n  say\n  hello\n  earthlings\n);\n</code></pre>\n\n<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>\n\n<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>\n"}, {'answer_id': 90077, 'author': 'Swati', 'author_id': 12682, 'author_profile': 'https://Stackoverflow.com/users/12682', 'pm_score': 2, 'selected': False, 'text': "<p>Asking them to write a <strong>recursive algorithm</strong> for a well known iterative solution (i.e. Fibonacci etc. -- we give them an iterative function, if needed) and then have them compute the run time for it.</p>\n\n<p>Many times the recursive function involves a tree data structure. The number of times the person has failed to recognize that baffles me. It becomes slightly difficult to calculate the run time until you can see that it's a tree structure...</p>\n\n<p>I find that this problem covers many areas. Namely, their code-reading ability (if they are given an iterative function), code-writing ability (since they write a recursive function), algorithm, data-structure (for run-time)...</p>\n"}, {'answer_id': 126663, 'author': 'Xavier Nodet', 'author_id': 4177, 'author_profile': 'https://Stackoverflow.com/users/4177', 'pm_score': 3, 'selected': False, 'text': '<p>Implement a function that, given a linked list that may be circular, swaps the first two elements, the third with the fourth, etc...</p>\n'}, {'answer_id': 126721, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 4, 'selected': False, 'text': '<p>This doesn\'t necessarily touch on OOP capabilities but in our last set of interviews we used a selection of buggy code from the <a href="http://www.gimpel.com/html/bugs.htm" rel="noreferrer">Bug of the Month</a> list. Watching the candidates find the bugs shows their analytical capabilities, shows the know how to interpret somebody elses code</p>\n'}]
['https://Stackoverflow.com/questions/58354', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/3957/']