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.
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.
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.
(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.
"Draw for me on the whiteboard the design of the last project you worked on, without revealing me any sensitive detail."
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
{
get;
}
IBinaryTree<T> Right
{
get;
}
T Data
{
get;
}
// 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
{
get
{
return this.left;
}
}
public IBinaryTree<T> Right
{
get
{
return this.right;
}
}
public T Data
{
get
{
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:
Implement strcpy
, strcmp
and friends.
strdup()
.
strrev()
or string reversing function. My white-board solution impressed them and I am doing job now.
Two questions that have elicited interesting whiteboard discussions for me are
They start off simple and then get progressivly more complex.
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..)
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.
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:
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.
It's language independent.
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.
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.
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.)
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
).
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.
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.
Over and above that, I tend to ask them to knock up an algorithm for generating all combinations of a variable length data set.
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
)
SELECT CASE WHEN n % 3 = 0 THEN
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)
Console.Write("Fizz");
if (isDivisibleBy5)
Console.Write("Buzz");
if (!isDivisibleBy3 && !isDivisibleBy5)
Console.Write(number);
Console.WriteLine();
}
C# (clever)
Enumerable
.Range(1, 100)
.Select(i =>
i % 15 == 0 ? "FizzBuzz" :
i % 5 == 0 ? "Buzz" :
i % 3 == 0 ? "Fizz" :
i.ToString())
.ToList()
.ForEach(s => Console.WriteLine(s));
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)
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.
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.
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 :)
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.
Commented
Feb 26, 2011 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:
(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).
SELECT min(ID), Name FROM Things GROUP BY Name
would work, right?
Commented
Dec 20, 2010 at 16:46
HAVING count(Name) > 1
, but then I guess your sample answer should omit Bodkin Van Horn, Hot Shot, Snimm, and Dave.
Commented
Dec 20, 2010 at 20:54
DELETE FROM Things WHERE ID NOT IN (SELECT MIN(ID) FROM Things GROUP BY Name)
. Do you have a preferred solution?
Commented
Jan 12, 2011 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
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.
varargs()
or some function like that. Am I correct? I've only done it once to say I did it a while ago.
Commented
Nov 24, 2010 at 14:45
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.]
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.
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.
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.
How would you represent a standard 52 card deck? Any programming language is fine. How would you shuffle the cards?
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.
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?