Just as the title says, what is your favorite whiteboard interview problem, and why has it proven effective for you?

Junior, senior, Java, C, Javascript, PHP, SQL, pseudo-code, etc.

closed as not constructive by user8 Oct 29 '11 at 21:16

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

locked by yannis May 22 '14 at 8:39

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

  • 4
    A problem I hated was an Einstein's Puzzle. stanford.edu/~laurik/fsmbook/examples/Einstein'sPuzzle.html I could not do it in 30 minutes. But then I got pissed off, and found this: games.flowix.com/en/index.html So I trained to do a harder 6 x 6 x 6 problem on average in 20 minutes. I think I can handle 5 x 5 x 5 in 30 minutes now. Whatever stupid puzzles the employer will throw at me - I will remember them and will ace them next time. There are so many good puzzles. – Job Nov 23 '10 at 20:59
  • 20
    @Job: None of which will tell you anything about how an employee will perform on the job. Unless, of course, you spend all of your work time solving these kinds of puzzles instead of getting actual work done. – Robert Harvey Nov 23 '10 at 22:30
  • 1
    @Robert Harvey you mean you are in a business that makes money some other way than solving puzzles? I had no idea... ;) That puzzle is fun though. As a side note, a company I used to work for used actual IQ tests as the first step in their screening. I'd like to find some good whiteboard questions to separate the best candidates, not to simply screen them. – Nicole Nov 24 '10 at 5:31
  • 4
    @Renesis: As a developer, I can see how solving a puzzle identifies problem solving and analysis skills, but developers also must know how to translate that solution into code. Solving a puzzle only shows half of that execution. It's the difference between solving a Rubix cube and writing an algorithm to solve a Rubix cube. – Robert Harvey Nov 24 '10 at 6:13
  • @Robert Harvey I agree, I am specifically looking for coding problems, not just thinking problems. – Nicole Nov 24 '10 at 7:06

28 Answers 28

up vote 22 down vote accepted

I ask the candidate to design a solution to a problem I actually encountered in my day to day work. Doing so, I try to create a dialog between me and the candidate. I try to discuss about the design he is building as if I had never thought about the problem before.

What I try to evaluate is whether we are able to understand each other, and whether we can talk about a technical problem without confusion.

Concrete example

(For a java desktop developper)

Design an API to handle the navigation history of a web browser (previous page, next page, list the 10 previous pages), and that can be reusable in many parts of the application (here I give concrete examples in our app). Then, sketch up an implementation.

I like this one, because it's simple enough, it's easy to illustrate, it can be solved step by step (add additional behaviors without breaking everything), it allows to talk about edge cases and error handling, and it also allows to talk about data structures.

I've found this one extremely illuminating when interviewing candidates and filtering out those with no business being there. It is similar in complexity to Fizz Buzz, but focuses on database skills.

Assuming the following basic  table structure
Documents (DocID, DocDate)
Keywords (KeyWordID, KeyWord)
DocumentKeywords (DocID,KeywordID)

Write a query to return the following:
Part 1: Documents with a DocDate after 4/1/1995  
Part 2: Documents that contain the keyword "Blue"  
Part 3: Documents that contain the either the keyword "Blue" or "Yellow"
Part 4: Documents that contain the both the keywords "Blue" and "Yellow"

I let them write it in any SQL variant they want, and am not too picky on minor syntax problems. I mainly want to know that they understand basic relational DB concepts.

Most candidates can get through part 3 with no issues at all. You'd be amazed how many think that the answer to part 4 is just to change the operator from OR to AND in the where clause.

  • 2
    Ah, I see the issue w/#4. Your documents only have one keyword per row, so you can't have a cell equal both "Blue" and "Yellow" taps knows knowingly – glasnt Nov 23 '10 at 23:59
  • 8
    Ooops! I can see myself falling for (4) in an interview. @Job: As interviewer, I'd ask the candidate to explain the query, hoping that he stumbles over his problem to see how he deals with that. (that usually tells you more than a candidate acing your questions on first try.) – peterchen Nov 24 '10 at 16:03
  • 3
    @Renesis, I'm not so sure this is really digging deep. This seems pretty good for finding out if someone has basic SQL query skills. I'm actually shocked at how few developers have these basic skills these days. – Mark Freedman Dec 20 '10 at 16:36
  • 2
    @jk01, maybe I have an old school attitude about this, but IMO a well-rounded developer should have some DB knowledge, if not to access via code, but to at least understand the domain by experimenting with queries. Without this, a developer has a pretty significant blind spot. It's also EXTREMELY useful for system support and troubleshooting. Abstraction is fine to help simplify development and increase productivity, but I've seen way too many assumptions made because this is so often abstracted away. I could go on, but this could be a whole other debate I'm sure is taking place elsewhere ;) – Mark Freedman Dec 20 '10 at 18:50
  • 4
    @back2dos - Look, don't get offended just because you can't answer it. There may be a lot of other technologies that make this simpler, but we use a lot of SQL databases and I recruit people that know how to use the technologies we use, not make excuses for why they shouldn't have to answer my interview questions. – JohnFx Dec 23 '10 at 17:00

"Draw for me on the whiteboard the design of the last project you worked on, without revealing me any sensitive detail."

  • How would you define the design? Are you looking for a class diagram? Another UML diagram? A basic sketch of the tiers? – justkt Dec 20 '10 at 19:42
  • 1
    I call them baloongrams. ;) Just draw cicles, put names and connect them with named arrows. I don't care about his application but about the fact he understood it. – Uberto Dec 20 '10 at 21:00
  • 5
    +1. For people, who had a job previously, this is definitely one of the best things you can do. If they can explain how the project was structured, its already worth a lot. If they have an idea as to why it was structured in that particular way, or how some things could be done better, than this is really a huge plus. – back2dos Dec 23 '10 at 10:05
  • 3
    @justkt: The importance is, that the interviewee gets the information accross. It matters little how. I have met people, who really know UML, who can't explain a thing with it, and people, who can explain complex systems with a few squiggly lines. – back2dos Dec 23 '10 at 10:10
  • 2
    How on Earth is anybody supposed to draw the design of a project without revealing any sensitive detail? – Nemanja Trifunovic Feb 15 '11 at 15:30

Implement strcpy, strcmp and friends.

  • 4
    I ask candidates to implement atoi(). – chrisaycock Dec 22 '10 at 5:25
  • 2
    You would be amazed at how many people can't implement strdup(). – Tim Post Dec 22 '10 at 16:16
  • 10
    That's only fair if the job opening is for a C programmer. – user1249 Dec 24 '10 at 23:16
  • In the interview for my current job, interviewer asked me to implement strrev() or string reversing function. My white-board solution impressed them and I am doing job now. – Gulshan Dec 26 '10 at 17:38
  • @crisaycock atoi() is easy. itoa() is devious – Michael Brown Mar 14 '11 at 4:51

My favorite which encompasses a few disciplines is to count the number of nodes in a binary tree given the interface (in C#):

public interface IBinaryTree<T>
    IBinaryTree<T> Left

    IBinaryTree<T> Right

    T Data

    // Other properties and methods not germane to this problem.

and just for fun, here's the implementation, though the interviewee need not see this.

public sealed class BinaryTree<T> : IBinaryTree<T>
    private readonly IBinaryTree<T> left;

    private readonly IBinaryTree<T> right;

    private readonly T data;

    public BinaryTree(
        IBinaryTree<T> left,
        IBinaryTree<T> right,
        T data)
        this.left = left;
        this.right = right;
        this.data = data;

    public IBinaryTree<T> Left
            return this.left;

    public IBinaryTree<T> Right
            return this.right;

    public T Data
            return this.data;

    // Other properties and methods not germane to this problem.

and the assistant class:

public static class BinaryTreeNodeCounter
    public static int CountNodes<T>(this IBinaryTree<T> tree)
        // TODO: What goes here?

The solution I like to see is this:

public static class BinaryTreeNodeCounter
    public static int CountNodes<T>(this IBinaryTree<T> tree)
        return tree == null
            ? 0
            : 1 + tree.Left.CountNodes() + tree.Right.CountNodes();

As it demonstrates knowledge of:

  • how a tree (binary tree in particular) works
  • the recursive definition of a binary tree
  • recursive methods and how base cases stop recursion
  • what counting a single node means
  • interfaces as a contract
  • (less important) knowledge of C# syntax:
    • generics
    • extension methods
    • ternary operator
  • Could it be an extension method? – Gulshan Dec 20 '10 at 8:56
  • In this day and age, yes. We were coding in VS 2005 at the time, hence the sparse syntax. – Jesse C. Slicer Dec 20 '10 at 13:26
  • Why use an extension method when you've got the source code for the original class? That's not what extension methods are for. – Batibix Dec 20 '10 at 17:06
  • 'spose I could have gone a level deeper and show the candidate an interface that this class implements. The gist is that the original class should not need to be modified - some entry-level developers would love to add stuff to the class to make the request "easier". – Jesse C. Slicer Dec 20 '10 at 17:22
  • holy crap that looks a lot like java! – nn2 Dec 23 '10 at 9:01

Two questions that have elicited interesting whiteboard discussions for me are

  1. "Please can you explain in as much detail as you like how a web browser gets a generated page"
  2. "Please explain how Java Hibernate works"

They start off simple and then get progressivly more complex.

  • 31
    ehi, I'm not even qualified to judge the answers... I think that for the second one you need 12 black candles and a goat... – Uberto Dec 20 '10 at 19:33
  • 4
    The second is easy, your OS saves the processor cache and stack and the contents of your RAM to the hard drive, and then restores it when the computer is turned back on. – Malfist Dec 22 '10 at 20:53
  • However, the first question could take days to explain. – Malfist Dec 22 '10 at 20:55
  • @Malfist I meant the Java Hibernate persistence framework. – Gary Rowe Dec 23 '10 at 7:40
  • 2
    @Paul Stephenson Yeah, but just to be sure... – Gary Rowe Dec 24 '10 at 11:46

I don't like to use a puzzle or a design question as a whiteboard question. I prefer straightforward, simple, questions, that test the candidate's ability to write some code. My favourites are:

1) Write a function to reverse a singly linked list. (It takes a while before they realise they need 3 pointers.)

2) Given a binary tree, find the depth of the binary tree. (This question tests their ability to write recursive code. Lets me check if they have their base case intact.)

3) Write a procedure for binary searching an array of integers. (Like Jon Bentley says (in Programming Pearls), many people tend to make mistakes writing binary search. One can then follow up with finding bugs, writing test cases, running through the code, etc..)

  • +1, I like your approach doesn't make any sense to ask someone Dynamic programmins or such concepts when they are hardly used in business programming + Emphasis should be on code quality as well and not on the solution alone. – Geek Dec 23 '10 at 8:50
  • I don't mind design questions, but I once interviewed with a guy whose hobby was doing puzzles, and he had some horrid questions. It was like me asking somebody martial arts questions. – Bob Murphy Dec 23 '10 at 17:42
  • Probably should make sure people know you mean "sorted array" in (3) right? – HaveAGuess Jul 12 '13 at 15:43

We used this at one company I worked for.

We handed the candidate a piece of paper used for tracking time. It was a real timesheet used by one or our divisions. We asked the candidate to walk us through the design process for creating a better time tracking tool. No boundaries, didn't say what language etc., just want to see how good the candidate was at "full lifecycle". It gave us a real insight into how they gathered requirements. How they structured database tables, what kind of UI they might do. Communication skills were obviously needed for this task. It was usually done in a room with several large white boards and lasted as long as 2 hours.

We hired several people using this process and if they did really well on the task they did really well for us. If they were marginal and we decided to hire them anyway (separate topic) they were marginal programmers.

I use a problem that is relevant to my programming domain.

If I develop web applications, I want to see how they might draw up a web form that deletes records, and what approach they might take to removing the record from the database, for example. This tells me if they know basic database principles, how they interact with the user to verify deletion, and if they know what a soft delete is.

I don't have a favorite. The problem I choose will vary greatly depending on the job.

I don't care whether they can solve the problem completely or not in an interview, what technologies and languages they use, or how crappy their code looks on a whiteboard. I am looking for a thought pattern; I want to see if they know how to think through and solve problems.

  • 2
    +1 For the last paragraph, which is all important. Usually it is not the answer that matters in such things, but the path taken to get there. As all my maths teachers ever said "show your working!" – Orbling Dec 22 '10 at 13:33

My favourite was one a friend of mine used.

Write me a function to generate/print/store the first "n" prime numbers and then explain how it works and how efficient it is.

It works well because:

  1. It's an algorithmic question so it requires the interviewee to be able to think and then explain their thinking - so you can see how their brain works.

  2. It's language independent.

  3. Hardly anyone gets it completely right (there's usual an edge case they miss (1 or 2 normally), or they don't handle negative numbers, so you get to see how they handle bugs and being told that they're wrong.

  4. Most do it as a simple but very slow sieve (e.g. 80% of people will check of n is a prime by dividing n by all integers less than n), which gives you lots of scope for conversations about how they could improve the algorithm based on space/time trade offs e.g. "why are you dividing a number by 4 if you already know it's not divisible by 2?" or "You've worked out that you only need to divide by all prime numbers less than sqrt(n), but that requires you to store those numbers somewhere, so what are the implications of that?")

There's no need for them to get the answer right. If someone can think and explain their thinking then they're a long way down the road for being a good candidate.

  • I once got an interview question, where I was given a very obfuscated block of C code, and asked to find out what it did. In a very round about way it printed every other prime number out. 300 people applied and they offered me the job as apparently I was the only candidate that told them what the purpose of it was, as opposed to getting the values out. So yes, +1, primes are a good check. Particularly if they come up with a sieve, though that trades off computational complexity for space complexity. – Orbling Dec 22 '10 at 13:14
  • 1
    1 isn't prime.. – user1249 Dec 24 '10 at 23:21
  • 2
    @Thorbjørn - well obviously, but a good percentage of the routines I've seen written to solve this problem have told me that it is – Rhys Gibson Jan 4 '11 at 8:42
  • then they have a bug :) – user1249 Jan 4 '11 at 9:03

Something called aff_z, which was part of my engineering school's C examinations and was used as a "dummy" test to have students fail when coming back from holidays (our marking system implied that failing a test stopped the marking, so failing that dummy test would invalidate your whole test. Forces you to pay attention to moronic details). I did reuse it once or twice during interviews.

Anyways... I forgotten the exact formulation but it was something like this...

Write a function taking a single char parameter named c and returning nothing (void).
You function must satisfy the following requirements:

 - if c is bigger or equal to 0, then print 'z' to standard output
 - if c is stricly smaller than 0 , then print 'z' to standard output
 - in any other case, print the letter 'z' to standard output

The sad thing is that not only some students would come up with extremely convoluted solutions when the answer is fairly obvious, but that some would even manage to fail.

And believe it or not, it did happen during interviews as well.

Running it in interviews was fairly fun, as some applicants would start writing the possible branches and then realize what is wrong (obviously, if you only ask them orally, that is quite understandable that they do so as you speak... but if you give it in writing, I find it puzzling...)

It's dumb, but I guess it's a minimalistic screening (similarly, when hiring JS programmers, I always ask how to declare a variable, and then depending on their answer whether or not using var makes any difference at all. Quite often a sad moment, honestly.)

  • 1
    Did you ever have candidates in interviews feel insulted by this? Or think you were simply having fun at their expense instead of conducting a serious interview? – Nicole Dec 20 '10 at 6:48
  • @Renesis: I had a few looking at me with a smirk first. Some of which failed the test. In general the good candidates laugh if off. For the JS programmers for instance, I had quite a lot of candidates who failed the interview answer with a "duh, variablename = variablevalue;" whereas the good ones would just laugh on the phone or in person and directly tell me what the different would be with or witout var). – haylem Dec 20 '10 at 11:45
  • 1
    @Renesis: Plus, I couldn't really care less if some get offended . It's not discriminative in any way. If they get offended, then I'll assume they're the kind of person who don't like to be put to the test or questioned. I never really had applicants feeling I had fun at their expense though. I usually even apologize before asking very simple questions as it might feel like a waste of time for the good ones. But the thing is, it's not a waste of time for me. Not asking them would ne, on the longer run. – haylem Dec 20 '10 at 11:48
  • @Renesis: And more often that not, what I got after the smirk/laugh/offended look was an ashamed expression and an apology from the one who failed it or started writing the branching for the whole test when they realized it was useless. Yes, I do have some fun giving this test, but I wouldn't give it if it wasn't for a good reason. – haylem Dec 20 '10 at 11:50
  • Personally, I would have a mental facepalm when reading that and would wonder if someone else wrote the question for the interviewer to make fun of him. – wildpeaks Dec 21 '10 at 21:27

It really depends what you are looking for, as an organisation that does a lot of dynamic web work involving images, I tend to like to ask a geometry question pertinent to the job. In any case, I tend to ask a geometry question, as I find it a good maths test that is nice and visual and can show a candidates ability to visually present their working and methodically work through a problem.

For advanced candidates, I occasionally give the following question:

This image shows a crescent moon. The width of the crescent from B to D is 9cm and between E and F, 5cm. C is the centre of the larger circle.

a) Please calculate the area of the crescent. Crescent Moon Maths Question

b) Describe the calculations necessary to resize an image to fit in to the inner circle from any given size, and position it within the circle if the centre point is known.

For an easier question I usually give the same sort of question, but use the "square within a circle within a square" example. Though this is very easy, so I would expect perfect algebra on it.

Square inside a circle inside a square

Over and above that, I tend to ask them to knock up an algorithm for generating all combinations of a variable length data set.

  • 1
    The answer for a) is 128.75? (don't know if I made any mistake). I like it, but it's more about geometry though. – Hoàng Long Dec 22 '10 at 8:41
  • 2
    Also, sorry for the delay in commenting. I don't like to downvote as a rule and doubly so without commenting as to why. My downvote isn't about the question itself, it certainly has purpose for you, I just don't think it has a proper context in a programming interview. – Philip Regan Dec 22 '10 at 14:47
  • 7
    -1 because geometry is a good candidate for Just In Time Learning, and does not reflect on my ability to create quality software. – Malfist Dec 22 '10 at 16:38
  • 2
    I enjoyed this problem. I hope you don't mind me sharing my solution to part (a). The diameters differ by 9cm, so if the inner circle has radius r, the outer circle has radius r + 4.5. The area of the crescent is the difference in the areas of the circles: pi(r + 4.5)^2 - pi * r^2. All that's left is finding r. Define C as the point (0,0), then point E is at (0, r - 0.5) (because CE is 5cm less than the larger radius). The inner circle is shifted right 4.5cm, so its equation is (x - 4.5)^2 + y^2 = r^2. Plug in (x,y) = (0, r - 0.5) and solve for r. – Tim Goodman Feb 26 '11 at 21:53
  • 2
    +1 because I think it's a good question for a job that requires geometry. There's plenty of reasoning involved, not just plugging into a formula. That said, I know some good programmers who'd be tripped up just because they haven't so much as had to think about circles in 10 years -- but the question doesn't ask for a suitable question for any developer interview. The currently top-voted SQL question (which I also like) is at least as job-specific. – Tim Goodman Feb 26 '11 at 22:13

The best FizzBuzz answers I've seen are:

SQL Server 2008

;WITH mil AS (
 SELECT TOP 100 ROW_NUMBER() OVER ( ORDER BY c.column_id ) [n]
 FROM master.sys.all_columns as c
 CROSS JOIN master.sys.all_columns as c2
             CASE WHEN n  % 5 = 0 THEN 'FizzBuzz' ELSE 'Fizz' END
        WHEN n % 5 = 0 THEN 'Buzz'
        ELSE CAST(n AS char(6))
     END + CHAR(13)
 FROM mil

C# (simple)

foreach (int number in Enumerable.Range(1, 100))
    bool isDivisibleBy3 = (number % 3) == 0;
    bool isDivisibleBy5 = (number % 5) == 0;

    if (isDivisibleBy3)

    if (isDivisibleBy5)

    if (!isDivisibleBy3 && !isDivisibleBy5)


C# (clever)

  .Range(1, 100)
  .Select(i =>
    i % 15 == 0 ? "FizzBuzz" :
    i % 5 == 0 ? "Buzz" :
    i % 3 == 0 ? "Fizz" :
  .ForEach(s => Console.WriteLine(s));
  • 1
    You may want to add which particular SQL dialect this is written in. – user1249 Dec 24 '10 at 23:25
  • Looks nice with the functional style. – Orbling Dec 24 '10 at 23:57

I look for a couple of things in candidates that I have interviewed. For reason I can't describe online, we get pretty poor candidates, and I've come to expect it, so I'm pretty easy on them. Even still, I look for:

  • Awareness of design.

    "Show me the table structure for an address book program that has Contacts with first and last names that can have multiple Phone Numbers with a description of the number (cell/home/work/etc.)"

    I'm not looking for a UML 2.0 spec diagram here, a simple bubble diagram here is fine. As long as it's reasonable.

  • Knowledge of working with a database (ie. SQL)

    1. Write a query to get all of the phone numbers for people with the last name "smith"
    2. Write a query to get all of the customers in the database, and the phone numbers for the ones with the last name "smith"
  • Knowledge of testing

    Assume a method with the signature public IEnumerable<PhoneNumber> GetPhoneNumbers(string lastName) exists that returns the results of your query from earlier. Assume that if you pass a null into the method, it throws a NullReferenceException. Write a test to demonstrate this functionality.

    Write a test that demonstrates that GetPhoneNumbers will return a home phone number of (123)456-7890 for someone with the last name "smith".

  • Knowledge of how to write some code

    Implement a method that will fulfill the requirements of the tests you wrote.

Considering the number and quality of the applicants we've gotten, I've interviewed everyone who's ever seriously applied. I've hired no-one.

  • In SQL #2, are you talking about doing this all in one query? Is the purpose just to gauge understanding of left/right or inner joins? – Nicole Dec 20 '10 at 8:12
  • @Renesis: Yes it is. – Steven Evers Dec 20 '10 at 8:20

I usually let them sketch a block diagram of the last system they've worked on, asking about the relations between the blocks and than let them elaborate on the block they were working/in charge on. You can learn many from this exercise, like how one looks beyond his small domain, how much is it important to him to know 'where' he is acting, also you can learn about the role he was playing, was it a key or side role.

Write an algorithm for the following problem: Given a number n, output the total number of (unique) binary trees that have n nodes.

Thus, for n=0 and n=1, the answer is 1. For n=2, you have 2: the root node, and then the second node either to the left or the right.

You can gain insight into design techniques and to see if they think of recursion or memoization or the dynamic programming solution.

[See also this StackOverflow discussion for the related, but different, case of binary-search trees.]

  • So a UI Programmer who doesn't know dynamic programming is a bad programmer ? For the heck of it any business programmer who can't recollect dynamic programming is bad ? A lot of teens at topcoder will walk through a dynamic programming problem but please have a look at the code they write. – Geek Dec 23 '10 at 8:47
  • @Geek: Remember that "whiteboard" problems are a way to see someone's thought process. Dynamic programming problems should belong in this discussion, as they are very popular with Google, among others. – Macneil Dec 23 '10 at 12:51
  • I don't disagree but I have two questions. 1. Solving the unknown ? DP problems become a walk in the park if you have solved some problems in the recent past or you still remember the concept out of college. Someone who has forgotten it will definetely not do well on the white board. 2. If someone is struggling to solve a problem there is no way you can quantify his code quality. What about giving a problem on something like a LinkList or Strings or Arrays such that the person can solve the problem and write code. – Geek Dec 24 '10 at 7:29
  • I wouldn't necessarily expect an interviewee to get it right, either, however some companies will. – Macneil Dec 24 '10 at 14:35
  • @Geek: “a … programmer who doesn’t know dynamic programming is a bad programmer?” – yes. That said, I agree that thinking in dynamic programming isn’t trivial when you’re not used to it. But knowing it is an absolute must. – Konrad Rudolph Dec 24 '10 at 22:31

If I were to interview a software developer, I'd ask him to design a software and describe hardware requirements to remove duplicate entries from an arbitrarily large file containing a full name on each line. I leave some parts of the problem description ambigous purposefully. Then I challenge him to see if he understands analysing and clarifying requirements, different trade-offs, data structures and algorithms, I/O (secondary storage), software and hardware technologies, scalability, etc.

I think it is a small yet challenging problem, revealing applicant's knowledge and abilities in many computing areas.

Implement function/method(on c/c++/c# whatever), which calculates n-th item of Fibonacci sequence

Many guys could stuck on this. If some solution is given - usually it uses recursion. After that:

Implement the same via 'for'-loop

Can't tell you, how many fellows fail to complete both tasks - 50% of candidates.
That's why I like it :)

  • What if the first implementation is done via a for loop? – Darknight Dec 24 '10 at 20:06
  • 2
    Recursive version is proposed to implement. Usually after for-loop guys successfully implement recursive version. – alexb Dec 24 '10 at 20:20
  • Or you could implement this as a single statement: fib(n)=round(power(PHI,n)/SQRT5). PHI and SQRT5 are constants representing the golden ratio (1.618...) and the square root of 5, respectively. – oosterwal Feb 26 '11 at 4:02

For databases I go with:

Table: Things

ID       Name
1        Bodkin Van Horn
2        Hoos-Foos
3        Hoos-Foos
4        Hot-Shot
5        Marvin O'Gravel Balloon Face
6        Snimm
7        Marvin O'Gravel Balloon Face
8        Marvin O'Gravel Balloon Face
9        Dave

Write me some SQL that will de-duplicate a table like this based on the name (and I don't care which ID I get back but whichever one is returned must be valid for that name). So the table once the correct SQL has been applied to it will present something like:

Table: Things

ID       Name
1        Bodkin Van Horn
2        Hoos-Foos
4        Hot-Shot
5        Marvin O'Gravel Balloon Face
6        Snimm
9        Dave

I like it because:

  • De-duplication is a real world problem
  • There are a bunch of ways to do it
  • I think that pretty much all of those ways need you to either understand (slightly) more complex SQL (essentially GROUP BY and HAVING) or the ability to reason through chaining multiple simpler statements.
  • Because of this last bit even if they're struggling with syntax or whatever, you can ask them what they're thinking and talk through it that way.
  • It references Dr. Seuss

(This is where I find that there is some entirely trivial way of doing this and I've been over complicating it all these years).

  • 1
    I guess I don't know what counts as "entirely trivial"... Something like SELECT min(ID), Name FROM Things GROUP BY Name would work, right? – Tim Goodman Dec 20 '10 at 16:46
  • @Tim - That gives you the count for everything. I only want those with duplicates. Manually edited the results doesn't count, assume it's scaling to millions of rows. It is an easy problem but in my experience 80% of people claiming to know SQL can't get even as far as your first stab. – Jon Hopkins Dec 20 '10 at 16:49
  • @Jon: Not sure what you mean by "That gives the count for everything". From your example solution, it looks like what you want is one row for each distinct name. From your comments it seems like maybe you mean something like HAVING count(Name) > 1, but then I guess your sample answer should omit Bodkin Van Horn, Hot Shot, Snimm, and Dave. – Tim Goodman Dec 20 '10 at 20:54
  • @Tim - You're right, it's really unclear. I'll edit when I get a few minutes. – Jon Hopkins Dec 21 '10 at 10:26
  • 1
    I guess I would do this: DELETE FROM Things WHERE ID NOT IN (SELECT MIN(ID) FROM Things GROUP BY Name). Do you have a preferred solution? – Tim Goodman Jan 12 '11 at 19:22

My favourite C++ whiteboard problem is to have the candidate implement

Vector3 a(1, 0, 0), b(0, 1, 0); // Mathematical 3D vectors
double c = 7.0;
double d = a * c;
Vector3 e = a * b;

From this I can learn

  • if the candidate recognises that you can't overload on return type (indication of juniour-level C++)
  • if the candidate knows how to return a temporary and implement casting operators (indication of intermediate-level C++)
  • if the candidate can do basic vector math (important for our application domain)

How would you represent a standard 52 card deck? Any programming language is fine. How would you shuffle the cards?

  • vector<Card> with C++' shuffle function :) – rightfold Sep 5 '11 at 21:41

My favorite is to start with asking the prototype of printf. Then given a low level API printc(char c), which will print one character, implement printf. Gives all sorts of interesting responses like the stack is part of the CPU. As you might have guessed I am from a C and embedded background.

  • I don't get the "stack is part of the CPU" thing. – barjak Nov 24 '10 at 13:28
  • Anyone who knows anything about computer architecture would know that. To me it's completely unrelated, so the guy is demonstrating his ignorance. – Michael K Nov 24 '10 at 14:43
  • @aufather: If I remember correctly, you have to call varargs() or some function like that. Am I correct? I've only done it once to say I did it a while ago. – Michael K Nov 24 '10 at 14:45
  • @barjak - Once you start implementing printf, you will need to access your stack, and I have got responses that stack is in the CPU. – aufather Nov 25 '10 at 3:58
  • @Michael - In the embedded world, you need to know your platform architecture really well. So this question quickly weeds out the ignorant pretty early on. – aufather Nov 25 '10 at 4:00

You have a bowl with 200 fish in it. Of these fish 99% are not guppies. How many fish should you remove so that 2% of what remains are guppies. Show your work.

This is about confusing requirements. It is said this way to change perspectives multiple times during the same question. It is meant to see if they can figure out what is really going on.

You would be surprised how many people get it wrong.

  • 4
    Add two 12 Inch Oscars in the bowl they will remove 98% of the guppies very soon. – Geek Dec 23 '10 at 8:51
  • What happens if you remove a guppy? – user1249 Dec 24 '10 at 23:33
  • 1
    1% guppies, = 200 x 1% = 2 (200-2 = 198 other fish), where 2 = 2%, remaining fish = 98% = 98 (1:1). 98 = 198 - 100 => answer = 100. [Assuming you can selectively pick the other fish. If removing guppies, there are other answers.] Good question, you would be surprised how few people handle that well, though it should be child's play for a programmer. – Orbling Dec 25 '10 at 0:02

I have a few favourites, but here are a couple that nearly always come up. Most of the time I'm doing final round technical (C++) interviews so favour longer and more open questions which lead to new areas of interest. There's no 'right' answer, just an opening to other conversation.

1) Implementing a basic shared pointer, explanations of where there's deficiencies compared to tr1 or boost's shared pointers in their implementation, how it should be used etc.

2) A code review. For experienced hires we expect them to be able to confidently review some provided code for design problems, errors, coding horrors and potential maintainability problems. Also, of course, how they'd fix it; and sometimes how they'd give that message to the junior developer they're shooting down.

One question that I've been using ever since it was used on me is the following:

Write a function to print all numbers between 1 and 100.

A large part of the reason that I've been using it is due to the fact that you can then take there solution and move in various directions:

How would you modify the function to print all numbers between 1 and 1000, 10000, or n ?

Their answers to these questions could give you insight as to how they respond to changing requirements as well as if they can recognize performance considerations. A strong candidate might respond with a question in regards to what the function is needed for an how often it would be called.

Moving in a different direction:

How would you change things if you knew this function is going to be called several times a minute and performance is a concern?

I use this as a way of checking their lateral thinking. Since calculating prime numbers can be slow as the max value gets larger it sometimes makes more sense to just use some sort of calculated or pre-calculated look-up table that is adjusted on the basis of the problem you are trying to solve.

Here's one to provoke some thought--It's straightforward, involves a bit of math, and checks the candidate's knowledge of basic computer design (overflow, numeric representation, etc):

Write a program (or procedure) that takes a pair of integers X, Y as input and determines whether X*Y is evenly divisible by 10. IMPORTANT NOTE: X and Y may be large enough that X*Y overflows the largest integer type available on your machine.

Sample solution:

T_BOOL MultipleOfTen(int x, int y)
    return((x%2==0 || y%2==0) && (x%5==0 || y%5==0));

Fill in the following method: PS A mode of a number is the number (in the list) which has the most occurrences.

public int getMode(List<Integer> numberList) {


This is to see of effecient is your code.

How would you represent a spare matrix that's relatively large... say 1000x1000 but has at most 100 non-zero entries?

protected by ChrisF Feb 26 '11 at 12:44

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.