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.
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.
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.
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've found checking a string if it is a palindrome is a pretty simple one that can be a decent weeder.
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.
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 ?
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."
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.
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).