Anybody have any good FizzBuzz type questions that are not the FizzBuzz problem?
I am interviewing someone and FB is relatively well known and not that hard to memorize, so my first stop in a search for ideas is my new addiction SO.
Anybody have any good FizzBuzz type questions that are not the FizzBuzz problem?
I am interviewing someone and FB is relatively well known and not that hard to memorize, so my first stop in a search for ideas is my new addiction SO.
I've seen a small list of relatively simple programming problems used to weed out candidates, just like FizzBuzz. Here are some of the problems I've seen, in order of increasing difficulty:
These were for Java, and you could use the standard libraries so some of them can be extremely easy (like 6). But they work like FizzBuzz. If you have a clue about programming you should be able to do most pretty quickly. Even if you don't know the language well you should at least be able to give the idea behind how to do something.
Using this test one of my previous bosses saw everything from people who aced it all pretty quick, to people who could do most pretty quick, to one guy who couldn't answer a single one after a half hour.
I should also note: he let people use his computer while they were given these tasks. They were specifically instructed that they could use Google and the like.
Perhaps this does not answer your question directly, but I am not certain you need to come up with another problem. Besides being "easy to memorize", the FizzBuzz question is just plain "easy", and that is the point. If the person you are interviewing is in the class of people to which FizzBuzz is "well-known", then they are in the class of people that a FizzBuzz-type question would not filter out. That does not mean that you hire them on the spot, but it does mean that they should be able to breeze through it and get on to the meat of the interview.
To put it another way, anybody who takes the time to read Coding Horror is worth interviewing further. Just have them write out the solution really quickly, discuss it briefly (e.g., How do you test this?), and then move on to the next question. And as the article says, "it is genuinely astonishing how many candidates are incapable of the simplest programming tasks."
Any of the early ones from Project Euler would probably be good.
For example:
Problem 25
The Fibonacci sequence is defined by the recurrence relation:
Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.
Hence the first 12 terms will be:
F1 = 1 F2 = 1 F3 = 2 F4 = 3 F5 = 5 F6 = 8 F7 = 13 F8 = 21 F9 = 34 F10 = 55 F11 = 89 F12 = 144
The 12th term, F12, is the first term to contain three digits.
What is the index of the first term in the Fibonacci sequence to contain 1000 digits?
I've found checking a string if it is a palindrome is a pretty simple one that can be a decent weeder.
I wanted a FizzBuzz question that doesn't involve the modulo operator. Especially since I'm typically interviewing web developers for whom the modulo operator just doesn't come up that often. And if it's not something you run into regularly, it's one of those things you look up the few times you need it.
(Granted, it's a concept that, ideally, you should have encountered in a math course somewhere along the way, but that's a different topic.)
So, what I came up with is what I call, unimaginatively, Threes in Reverse. The instruction is:
Write a program that prints out, in reverse order, every multiple of 3 between 1 and 200.
Doing it in normal order it easy: multiply the loop index by 3 until you reach a number that exceeds 200, then quit. You don't have to worry about how many iterations to terminate after, you just keep going until you reach the first value that's too high.
But going backwards, you have to know where to start. Some might realize intuitively that 198 (3 * 66) is the highest multiple of 3, and as such, hard-code 66 into the loop. Others might use a mathematical operation (integer division or a floor() on a floating point division of 200 and 3) to figure out that number, and in doing so, provide something more generically applicable.
Essentially, it's the same sort of problem as FizzBuzz (looping through values and printing them out, with a twist). This one is a problem to solve that doesn't use anything quite as (relatively) esoteric as the modulo operation.
Fibonacci, reverse a string, count number of bits set in a byte are other common ones. Project Euler also has a large collection of increasing difficulty.
For something really super-simple that can be done in 10 seconds, but would remove those people who literally can't program anything, try this one:
Ask: show me (on paper, but better on a whiteboard) how you would swap the values of two variables.
This wasn't my idea, but was posted in a comment by someone named Jacob on a blog post all about the original FizzBuzz question.
Jacob goes on to say:
If they don’t start with creating a third variable, you can pretty much write that person off. I’ve found that I can cut a third to half my (admittedly at that point unscreened) applicants with that question alone.
There is a further interesting discussion after that comment on the original blog post about ways to perform this variable swapping without requiring a third variable (adding/subtracting, xor etc.), and of course, if you're using a language that supports this in a single statement/operation, it may not be such a good test.
Although not my idea, I wanted to post this here as it's such an elegantly simple, easy question that can (and should) be answered within about 10 seconds by someone who has written even the simplest of programs. It also does not require the use of somewhat apparently obscure operators like the modulo operator, which lots of people, who are otherwise fairly decent programmers, are simply not familiar with (which I know from my own experience).
Ask them to write an app to return the factors of a given number. It's easy to do and hard to do well in a short period of time. You can see their style and the way they think through problems in a small amount of time.
Return the index of the first occurrence of string X within string Y
Implementing strstr() requires a basic understanding of the language while providing the opportunity for clever optimization.
If it is a C/C++ interview make sure the person knows about pointers.
General - simple algorithm ([single/double]linked list). Ask about complexity of adding in each case (at the begining, at the end, optimizations ...) ?
(General) How do you find min and max from an array (N size) with just 3*N/2 comparisons?
C/C++: How would you optimize multiple "strcat"s to a buffer ?
Check out 6.14 from the C++ FAQ Lite:
http://www.parashift.com/c++-faq-lite/big-picture.html
How about: I want to use a single integer to store multiple values. Describe how that would work.
If they don't have a clue about bit masks and operations, they probably can't solve other problems.
Find a list of primes is a fairly common question but it still requires some thought and there are varying degrees of answers people might give.
You would also be surprised how many people struggle to implement a Map/Dictionary type data-structure.
I have asked my candidates to create a program to calculate factorial of a given number in any pseudo language of their choice. It is a fairly easy problem to solve and it lends itself well to the natural followup quistions (that could often be asked) about recursion.