views:

3430

answers:

36

Assuming:

  1. Typical interview stress levels (I am watching)
  2. Using familiar IDE and program language (their choice on their PC!)
  3. Given adequate explanation and immediate answers to questions
  4. Able to compile code and check answers / progress
  5. Claims to be a senior level programmer

How long should it take an interviewee to answer FizzBuzz correctly?

Edit: FizzBuzz: Write a program that prints the numbers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz".

Edit: It isn't so much that if they take more then X minutes they are disqualified, but I am curious if I should just cut them loose after they work on it for half hour.

A: 

A senior dev?? Maybe five minutes.

Jack Marchetti
A: 

As long as the rules for fizz-buzz are provided, probably no more than 5 minutes

Zak
+24  A: 

About a long as it takes for them to say "you really want me to write that down or just speak it aloud".

Kendall Helmstetter Gelner
Yeah, I was going to say "just as fast as they can say the answer."
Bill the Lizard
I think I would fail at saying the answer aloud. I'd code it, print the output and then read it aloud.
Daniel Daranas
@Daniel: "The answer" being the code, not the output it generates. :)
Bill the Lizard
My thinking was you'd say it just like on the podcast - loop, if statement, two modulo calls. If that's not enough you could flesh it out but if they even knew what modulo meant chances are they could do it quick enough.
Kendall Helmstetter Gelner
+17  A: 

It really depends on the dev - I don't like using time-based metrics in interviews for this purpose.

A great candidate could code FizzBuzz as fast as he could write and maybe wrap up in a minute.

Another great dev might clarify the requirements to ensure he doesn't miss anything, come up with a solution and talk through it, do a quick sanity check on it, write the code, and then spend another few minutes walking through the code and focusing on the corner cases to verify it works - taking much longer but delivering a very solid answer.

For your case knowing if you should cut them loose after 30 minutes, it should be pretty obvious if they are unable to make forward progress on this simple problem or if they are incapable of translating their ideas into code. Both are pretty straightforward and would result in me recommending no hire. At that point, I wouldn't cut them loose - I would be giving directed hints to wrap up this question and then either give them softball questions or just general discussion about their past projects. I might even still try to sell my company a little bit, to leave the candidate with a favorable impression that they could pass on to people they know who might want to apply.

Michael
It isn't so much that if they take more then X minutes they are disqualified, but I am curious if I should just cut them loose after they are working on it for a half hour.
Jim McKeeth
In that case, you would have observed their coding and problem solving skills for 30 minutes and whether or not you want to hire them should be pretty obvious.
Michael
+1 for turning the failure situation into a positive marketing opportunity
Tom Leys
+30  A: 

Hugh Jackman cracked the NSA database in 60 seconds with a gun to his head and a girl in his lap....so yeah, 5 minutes for FizzBuzz (max).

By the way, javascript 48 seconds (no code golf):

for(var i = 1; i <= 100; i++){
  var output = i + ": ";
  if(i % 3 == 0) output += "fizz";
  if(i % 5 == 0) output += "buzz";
  console.log(output);
}

Oops.

Didn't read the spec, I was wondering what people were complaining about. Ok, 2 hours later (guess I didn't get the job)

for(var i = 1; i <= 100; i++){
    var o = (i % 3 + i % 5 < 1 ) ? "fizzbuzz" : !(i % 3) ? "fizz" : !(i % 5) ? "buzz" : null;
    console.log(!(o) ? i : o);
}
Mike Robinson
In his lap is putting it mildly.
Jack Marchetti
+1 for a great answer.
Jordan S. Jones
Excellent. He'd do it in 10 seconds with its stupendous Hypercube IDE!
flq
IIRC the original definition of the problem requires the number NOT to be printed if it's a fuzz or a buzz or both - talk about being careful about requirements ☺
Ariel
@Ariel - Those numbers are a "feature" ;)
Mike Robinson
So we know it takes 48 seconds to solve it incorrectly.
Nosredna
Accepted and +1 for Swordfish reference.
Jim McKeeth
for (var i=1;i<=100;i++) { var output=""; if (!(i%3)) { output+="fizz"; } if (!(i%5)) { output+="buzz"; } if (!output) { output=i; } console.log(output);}
Nosredna
Sorry. Your super-numberful answer was driving me nuts. I fixed it in Chrome's console. :-)
Nosredna
@Nosredna - Touche
Mike Robinson
I took maybe 3 or 4 minutes. Sigh. Some of that was figuring out Chrome's console.
Nosredna
I like when people show off and FAIL :)
Jim
@Jim, we know he's a senior developer because he preemptively used a geeky film reference as a prophylactic against any coding mistakes he might make. I'd hire him based on his confidence alone.
Nosredna
What if you get it wrong, like this accepted answer?
sigjuice
@sigjuice, that's a question for meta.stackoverflow.com.
Nosredna
Hmmm... why do very few people realize that a number divisible by 3 AND 5 is a number divisible by 15?
Sudhir Jonathan
@Sudhir, I think people know that. Writing it with two constants makes it more obvious how to fix it when the spec changes. There's no "15" in the spec.
Nosredna
I like my answer because the 3 and the 5 are only in the code once, and there's no 15 at all.
Nosredna
A: 

Their choice of language on their PC? I'd say 3 minutes tops.

Eric Wendelin
A: 

I say they should be very close in 15 minutes. They may not have the exact program working but they should be very much on the right track by then. In 15 minutes you'll have a gauge on his skill level.

Cody C
If it takes fifteen minutes, I know how skilled the guy is compared to the skill expected of a senior developer.
David Thornley
+3  A: 

less than 5 minutes, probably 2 or 3 for pseudo code and 5 for something that would parse/compile

SQLMenace
+1  A: 

42 seconds.

Too short? How about 4.2 minutes then?

R. Bemrose
At least that's what Douglas Adams would say.
R. Bemrose
+8  A: 

Solving FizzBuzz is known to be NPC.

Danra
I think the Halting Problem has proven that it's impossible to detect if FizzBuzz will ever stop fizzing or buzzing.
rtperson
Bounded Fizzbuzz is big-Oh(n^.99999 repeating), for finite values on n.
Robert Lamb
+1 for profundity. I'd give you +2 if you said it in an interview.
Steve B.
+6  A: 

Like everyone else, I'd say about 5 mins or less. Jeff Atwood had a blog post about the apparent inability of many programmers to do this effectively.

Paul Dixon
+1  A: 

To quote the very blog you referred to "Most good programmers should be able to write out on paper a program which does this in a under a couple of minutes."

mfloryan
+22  A: 

I'd mentally count to three, by which time I would expect to have heard, "What, you're joking, right? I mean, you can't be serious..."

Then the next thing I should hear will be, "All right, you make a for loop..."

rtperson
IMHO, asking someone applying for a position as a senior developer for something like that is like asking someone applying for a job in finance if they know percent... I would think twice before taking the process to the next step after something like that, but that's me...
Fredrik
On the flip side, I once had a hiring manager request that I implement an entire FTP client before he'd so much as grant me an interview. I told him to take a hike.
rtperson
Wow. This is now the accepted answer? :-)
Nosredna
+6  A: 
RichieHindle
FryGuy
RichieHindle
Michael
First of all you used = instead of ==. Second, you initialized the i in the for statement which is illegal in C90, the version used in Visual Studio which you use. I think someone could tell if you are really a senior C developer from this.
Unknown
@Unknown: By "C" I meant "some ungodly hybrid of C and C++". I guess I don't get the job. Luckily I'm happy in my current job, playing a senior developer on TV.
RichieHindle
Is it legal to post prescriptions for medications as images this way?
Nosredna
And did you use a Ruffles potato chip in some innovative way when you built your homemade scanner? :-)
Nosredna
Really what TV show?
Unknown
@Nosredna: That was an unexpected and entertaining side effect of using a mobile phone camera under halogen lighting while under the influence of self-prescribed photocopied medication. I can't recommend it, to be honest.
RichieHindle
@RichieHindle--Did you barf?
Nosredna
Senior developer who writes a single equal sign (=) during comparison (==)? Seriously?
Artem Russakovskii
@Nosredna: Hey, the codebarf.com domain is available - maybe I should rehome my blog!
RichieHindle
@Artem: Yup. And then posts it to the Internet.
RichieHindle
How many bugs are there per lines of production code? The accepted answer isn't even correct! I bet RichieHindle would do better typing it into his IDE than he does scribbling it out. Great example that we don't get things right. Keeps us humble.
Nosredna
Shouldn't the paper be on a wooden table?
Jeanne Pindar
+6  A: 

How about 2 minutes, max? We aren't merely talking about competent developers, we're talking about senior developers.

Fizzbuzz is a trivial problem. Try it out yourself. I bet every 'senior' developer here can do it in under two minutes in the language of his/her choice.

theycallmemorty
Actually, a *senior* developer should have the humility born out of experience to know that there is no such thing as a trivial problem. I bet half the *senior* developers here wouldn't have gotten it right the first time, like Mike Robinson above.
Michael Borgwardt
When I was writing my rebuttal code to Mike's answer, I had "console.log(i)" instead of "console.log(output)". I ran it twice saying to myself, "what the hell?"
Nosredna
@Michael: When FizzBuzz first hit the blogosphere, a lot of people felt the need to show off their clever solution. Even without any time limit, *many* of those solutions were wrong.
Jeanne Pindar
+5  A: 

Yes, it's an easy, 5 minute problem -- but in an interview give them at least 10 minutes or even 15 because if the person wants to work at your company they are going to double check things and be very careful to get it right. If they are quick and careless about the test -- in what amounts to a high-stakes situation if they really do want the job -- that tells you something about them.

eeeeaaii
A: 

As a litmus test, FizzBuzz is a great one: If the interviewee actually answers constructively, FAIL:
I don't want to hire anyone who would tolerate such a useless question in an interview.

This would be a good question to gate acceptance into the "Programming II" class in 7th grade, though!


EDIT: Downvoted 3 times! Ha! FizzBuzz for a senior dev? 30 minutes? Seriously? If you asked me that in an interview I would walk out. That would make it very clear what kind of shop it was.

Cheeso
+1 from me. The only answer i agree with.
User
I can understand how this can be insulting, to a senior developer.
Liran Orevi
Unfortunately, you have to expect that many applicants will even fail such a simple test. A lot of people claim to have skills they clearly do not have, just to get the job. Simple tests like this one helps to get rid of them quickly.
ammoQ
OK, that's reasonable. So if they answer constructively, FAIL. IF they cannot answer, FAIL. If they scoff and walk out, I want to hire them. It's like a Willie Wonka test.
Cheeso
+1 I agree. Unless they say something along the lines of, "You are joking right?" and then proceeds to code without a choice after the interviewer's confirmation.
Cambium
Yep, that's a reasonable response....
Cheeso
You want to hire someone who walks out of an interview? Really?
James McMahon
Yes - that's what I mean by "the Willie Wonka test". you can only have it if you don't want it. But the point is moot for ME, because I would never ask a potential hire to code FizzBuzz.
Cheeso
"That would make it very clear what kind of shop it was." One that reads too many blogs?
jrockway
One that thinks senior developers should spend time on problems as vanishingly simple as FizzBuzz.
Cheeso
I don't think a senior developer should spend "time" on a question like this, but you would be surprised how many developers claim they are senior, but then take more than 5 minutes to solve it. I would expect them spend more time saying "are you serious?" and asking clarifying questions then writing the code. And if they walked out of the interview, then even better. I don't need **prima donnas** who are too full of their "senior developer status" to deal with some of the simple real world tasks that are involved in actual software development.
Jim McKeeth
+3  A: 

For a senior developer, about as fast as he or she can comfortably write or type. Brief pauses are allowable. Allow time for the candidate to realize what sort of thing you're asking, and deciding to go along with it.

The candidate may or may not look over the code briefly before compiling. That's permissible. Don't sweat typos.

If the candidate wants to write a header comment, fine, that's useful information.

If the candidate has significantly more trouble than I've outlined above, that's a bad sign. If the candidate takes more than a few minutes, it's time to thank the candidate for his or her time, and politely bring the interview to a close. No point wasting two people's time.

If the candidate is interviewing for a junior position, or is not using a familiar language and environment, you need to be more lenient. Still, if a candidate for any level of a developer position couldn't get it within ten or fifteen minutes in a reasonably familiar environment, don't hire.

David Thornley
+130  A: 

For a SENIOR developer 6-8 months.

First you have to pick a methodology, then you can start hiring the consultants that will pick the team.
But before you do that you need to choose where you want to go, the Rational Rose conference are in Hawaii but the Agile ones are at a golf course.

Then you need to get buy-in from the board at what your fizz and/or buzz strategy is, which means they will have to talk to the major investors and Wall St. But before they do that they will have to clear the whole thing with legal.

And long before anything is implemented you will have jumped ship for a better paid job - with all your new found board-level project experience you are worth much more than they are paying.

Meanwhile the list will be done manually on paper by an intern and typed into Excel by a secretary.

edit: there is a (semi) serious point - interview questions like this are of the 'jump in and start coding without asking any questions' type. What I want from a developer is someone who knows what questions to ask and how before they start typing away.

Martin Beckett
Now that's just an excellent answer! ^^
Arnis L.
exactly, awesome ;)
Ivan
(-1) I think your answer is clever, but the question the OP asked was a serious one.
Doesn't sound like any kind of dev to me, senior or not. Developers are in it for the code. You're describing a software architect.
Joe White
It's important to have fun, this answer rocks! He's describing a Senior SDE at many of the companies I'm familiar with :-) ~ imagine if he'd asked about an architect!
Jeff Wilcox
This made me laugh :)
Filip Navara
+14  A: 

As long as they are progressing towards the goal steadily, everything is good. Somebody might write the right code straight within a minute. Someone else might take more time in explaining his thinking, in factoring the code and in writing tests.

The end goal and time is not important. The important thing is the way to the goal.

For me it took just now some 10-15 minutes using TDD, the same way and quality that I would write production code. If I had written it just off the top of my head, it would maybe have taken one or two minutes (as I see other senior programmers have done it that quickly), but that would have been unprofessional. I wouldn't want to hire somebody who just hacks some code together.

That 10-15 min was about as fast as I could type, except at a couple of points where I was thinking about descriptive method names and afterwards I did some refactoring to make the code more expressive. I considered the alternative of concatenating "Fizz" and "Buzz", so that there would be one if less, but that made code less clean to me (maybe because of the mutable state), so I settled with the code below.

public class FizzBuzz {

    private static final int FIZZ = 3;
    private static final int BUZZ = 5;

    public static String textForNumber(int n) {
        if (multipleOf(FIZZ * BUZZ, n)) {
            return "FizzBuzz";
        }
        if (multipleOf(FIZZ, n)) {
            return "Fizz";
        }
        if (multipleOf(BUZZ, n)) {
            return "Buzz";
        }
        return Integer.toString(n);
    }

    private static boolean multipleOf(int multiplier, int n) {
        return n % multiplier == 0;
    }

    public static void main(String[] args) {
        for (int i = 1; i <= 100; i++) {
            System.out.println(textForNumber(i));
        }
    }
}


import junit.framework.TestCase;

public class FizzBuzzTest extends TestCase {

    public void test__Multiples_of_3_print_Fizz() {
        assertEquals("Fizz", FizzBuzz.textForNumber(3));
        assertEquals("Fizz", FizzBuzz.textForNumber(6));
    }

    public void test__Multiples_of_5_print_Buzz() {
        assertEquals("Buzz", FizzBuzz.textForNumber(5));
        assertEquals("Buzz", FizzBuzz.textForNumber(10));
    }

    public void test__Multiples_of_both_3_and_5_print_FizzBuzz() {
        assertEquals("FizzBuzz", FizzBuzz.textForNumber(15));
        assertEquals("FizzBuzz", FizzBuzz.textForNumber(30));
    }

    public void test__All_others_print_the_number() {
        assertEquals("1", FizzBuzz.textForNumber(1));
        assertEquals("2", FizzBuzz.textForNumber(2));
        assertEquals("4", FizzBuzz.textForNumber(4));
    }
}
Esko Luontola
multipleOf(int multiplier, int n) { return n % multiplier == 0; } - don't you think that's abit overkill?
Dave Rigby
OMG, if a developer wrote this much code for such a trival problem, for sure he would not get the job
Scott Weinstein
@Dave Rigby: That's the Composed Method pattern. The original method had code at more than one level of abstraction, so I moved the low-level integer fiddling into its own method and gave it a descriptive name (that also removed some duplication). See "Clean Code" chapter 3 or "Implementation Patterns" pages 77-79.
Esko Luontola
@Scott Weinstein: I wouldn't anyways want to work at a work place where they do not value quality. ;)
Esko Luontola
And unless they put forth some real interview questions after the trivial FizzBuzz, I might not want to work there either. You can't rate a person's skills based on FizzBuzz alone. That will only tell that somebody knows the basics of programming in some language.
Esko Luontola
Good answer to a rather dull interview question. I appreciate the levels of abstraction and the tests. Maybe I'd go a bit further, replace 100 by UPPER_LIMIT, and test some values of the whole sequence, e.g. UPPER_LIMIT == 0, 1, 5 and 10.
Daniel Daranas
Making things more complicated than they should be isn't exactly what I call "quality". For example, it's much more likely that some people might inadvertently swap the parameters of "multipleOf", e.g. write multipleOf(i, FIZZ), than that someone writes FIZZ%i==0.
ammoQ
Hey, great work! Let's see your complexity-hiding implementations of plus and minus while you're at it...
rtperson
@*, You are taking just the _only_ function whose usefulness is questionable as a basis to reject a piece of code which is very clear, easy to maintain and even the only answer which contains its own tests.
Daniel Daranas
@ammoQ: No production code is written without a test, so even if somebody would mix the order of parameters, the tests would find it out.
Esko Luontola
With a more expressive language (such as Haskell) it would have been possible to create a new infix operator "n isMultipleOf 5", which would have solved the ambiguity of parameter order, but with Java we need to be satisfied with the above code.
Esko Luontola
Now I know why Java programmers need IDEs that use 3 gigs of RAM...
jrockway
Nice idea adding the tests too. Wrapping n % multiplier == 0 (which is perfectly readable if you know Java) is just dumb IMO, +1 anyway. :)
abababa22
+4  A: 

It shouldn't take more than 2 minutes. There shouldn't be any pauses, except at the end to check your work. I see similar results with my candidates with another simple question:

Write a function to return the minimum number in an array

I'd estimate that about 75% fail this despite "years" of experience. Amazing how many people get by with drag and drop technology.

Jim
That has to be a result of interview nerves. I find it hard to believe that someone who can't find the minimum element of an array *can* get by with drag and drop.
Nosredna
If you get nervous by a for loop then you probably aren't going to be a very good fit in any development environment.
Jim
Then I guess the question is this: "Have they ever actually *done* anything? Or were they just sitting in a chair?"
Nosredna
@jim - how often are you required to write for loops to save your job with your boss watching over your shoulder timing you?
Jason
I've had candidates fail this one as well, and we're *really* picky about which CVs get as far as an interview. I asked my 80-year-old mother-in-law this question (having re-phrased it into a more real-world form) and she got it no problem.
RichieHindle
@Jason - Been there, done that, and done a lot lot more in interviews. This is just the first question to weed out the people who don't even belong in this career. If my boss wants to watch me do for loops or strategy patterns or whatever else, he's welcome to. I sit and pair program with my employees all the time. @RichieHindle - Yea, amazing huh? You'd figure 4 years of CS or engineering (plus a year or more of experience) and they could recite from memory "my first loop".
Jim
+1  A: 

Senior developer? It should be done in their head as the algorithm is described so however long it takes them to commit it to paper.

A: 

I just implemented this in C in just shy of 2mins (including compiling and fixing a couple of typos I made typing fast!), having not heard of the problem before. I'd like to consider myself a pretty experienced C/C++ dev, so anything in the order of 2~3mins seems reasonable, depending on typing speed etc - it's a pretty trivial problem.

Dave Rigby
+1  A: 

Just did it ...

class Program
   {
   static void Main(string[] args)
      {
      for (int i = 1; i <= 100; ++i)
         if ((i % 3 == 0) && (i % 5 == 0))
            Console.WriteLine("FizzBuzz");
         else if (i % 3 == 0)
            Console.WriteLine("Fizz");
         else if (i % 5 == 0)
            Console.WriteLine("Buzz");
         else
            Console.WriteLine(i.ToString());
      }
   }

Took me almost 5 minutes exactly. And I still had to fire up VS, figure out what the modulus operator was (I had forgotten which symbol it was in C#), and had a glass of water.

irb(main):002:0> start = Time.now
=> Tue Jun 30 13:38:08 +1000 2009
irb(main):004:0> finish = Time.now
=> Tue Jun 30 13:43:10 +1000 2009
irb(main):006:0> (finish - start) / 60
=> 5.03985

I'd say a senior should be able to do it in less than that. But I don't think there would be much difference between someone who does it in 4 or 3 minutes, as long as they don't take forever.

Remember people aren't machines ... they might have been out of work for a month or two, gone through a rough personal situation, be sleepy or otherwise just not in a programming mindset right that minute. Thats why I think the time doesn't matter too much as long as its not unreasonably long.

Nippysaurus
I like your comments about people not being machines. It's good to keep that in mind when interviewing, and understand that the day/hour of the interview may be one of the candidate's worst in a long time. But then you also need to identify the good candidates from the bad...
ecounysis
+77  A: 

Maybe it's not about how well they can code, but how they respond as a "Senior Developer" -- i.e., about 10 seconds after they start coding, inform them that 'fizz' is going to be replaced by some other word, TBD. Ten seconds after that, tell them that you need 'buzz' for multiples of 7 or 11, not 5, and that you will be counting to 1000 not 100. Ten seconds after that, begin asking them for status reports once every 30 seconds or so. If they can't make progress on the code while spending 45% of their time giving status, inform them you are going to bring in the next candidate and that they will be working together to try to make some better progress. Have another interviewer enter the room and ask distracting questions, like "how much re-use do you think we'll be able to get from this?" Tell them that ok, ok, fizz for multiples of 3 and buzz for 5 after all. If they are still with it 5 minutes in, be sure to make them transfer to "an identical platform" because it's time for technology refresh. etc.

If they can produce anything that remotely satisfies the requirements in under half an hour working like that, give them the job. =P

JustJeff
I wish I could upvote more than once.
Michael Borgwardt
+1 for accurately reflecting most real-life IT orgs. However, the best devs would have no interes working at a place that expects 45% of their time giving status reports.
AviD
Wow I think that pretty much describes the projects that I have worked on in its entirety.
futureelite7
Wow, you sound like a fun interview. After the 3d change I'd stop you and say "as the manageer for this project task do you think you could organize all of your requirements up front, please?" I mean, it's all fair to ask people "how would you modify that code to add the capability X" after it's written, but interrupting every 10 seconds is just the interviewer messing with you. I'm happy to code, but bullsh*t psych tests are a bit rude, really.
Steve B.
@SteveB - you did see where I put =P at the end there, I hope ..
JustJeff
@Michael Borgwardt: That can be arranged.
Bauer
Next, tell them to merge all these requirement changes through different branches of TFS!
Robert Jeppesen
+1  A: 

Am I the only one who thinks this is a piece of cake?

for (int i = 1; i <= 100; i++)
{
    if (i % 3 == 0 && i % 5 == 0)
        Console.WriteLine("FizzBuzz");
    else if (i % 3 == 0)
        Console.WriteLine("Fizz");
    else if (i % 5 == 0)
        Console.WriteLine("Buzz");
    else
        Console.WriteLine(i.ToString());
}

Is this supposed to be difficult?

Phoexo
nope... You are not alone.
Arnis L.
Why not change line 3 to "if (i % 15 == 0)"? 15 is the LCD of 3 and 5, so anything that is a multiple of 3 and 5 is also a multiple of 15.
A. Scagnelli
You can also put your EOL outside the If-Then block, so that FizzBuzz will concatenate together automatically. No need to check for multiples of 15 in that case, and you've saved yourself a few cycles.
rtperson
Its not supposed to be difficult, its supposed to prove that you are not a completely incompetent programmer.
Nippysaurus
+5  A: 
for(i in [1..100]) 
    x = ""
    if (i %% 3) x += "Fizz" 
    if (i %% 5) x += "Buzz"
    print x == "" ? i : x

~ 3 min

dotneter
For a moment - thought that you failed. ^^
Arnis L.
A: 

I spent about 5 minutes on the problem. For the most part, the "effort" was in identifying the likely "gotchas" in the question and making sure that I had them covered in the solution.

In general, coding questions during an interview always include some kind of gotcha to make the candidate think. Maybe the problem is missing information, and they need to ask questions to clarify exactly what is required. Maybe the problem is complete, but looks too easy.

FizzBuzz is a simple problem. There are two "gotchas" (such as they are): Has the candidate ever used the modulo operator? Will the solution still print the number when a word should be printed instead?

Beyond that, there are a few additional things that I would check in the final solution: will the loop actually run from 1 to 100, how will the solution handle the case where the number is both a multiple of 3 and 5...but teasing out details of how someone will approach a real problem from this example is more than a little stretch.

I am a slightly bigger fan of either pointer or bit manipulation questions during an interview, but most of the interviews I have done were for fairly low level C coding positions....so pointer and bit manipulation were important skills to have.

semiuseless
I want to meet these senior candidates who have never used modulo.
Nosredna
+2  A: 

Well, that's easy to calculate. I'll say time duration N and if you think:

It's less than what it should take: multiply N by 2.

It's more than what it should take: take average of N and N/2.

I mean, we're all developers here, why take wild guesses when we can apply a modified bisection method.

mannicken
A: 

I have never implemented FizzBuzz before, but I decided to try it as a one-liner in a nearby xterm. It took me about 30 seconds. My program produced the correct result on the first try.

If this takes anyone more than 5 minutes and they've heard of modular arithmetic before, don't hire them. (FWIW, the only time I use modular arithmetic in normal applications is for something like a progress bar; print '.' if $i % 1000 == 0 or something. Perhaps this is not the best thing to be testing for.)

jrockway
A: 

Last year at this time, and again now, we are interviewing to hire a Senior ASP.Net & SQL Server Developer. Last year we phone interviewed 20 guys, 19 were junk. This year we interviewed 10 candidates and 10 are junk.

The interviews go something like this.... we ask "tell me some of the different kinds of SQL Server joins." They say "left outer join, right outer join, ect" (sometimes you actually hear the pages of their notes turn)... then we ask a simple question that any developer should be familiar with if they have traveled the well worn path of development. We ask - if you had a table of customers and a table of orders how would you find the customers that had no orders? None of the 10 this year knew that - how could this be?

We would also ask what the difference between session state and view state were. All of them would spit back a book answer. Ok. Then we would ask: where is a view state variable stored. Now you are thinking that they just told us that so they will tell us again and we will all move on... nope. They spit back the book answer without fully understanding it. Five out of the 10 this year drew a blank on that question - yes, right after telling us the answer they could not answer it when it was rephrased. They are that unfamiliar with it.

I guess in some places it works out when you fake your way thru an interview - I have no problem firing someone that lied their way into a job.

JBrooks
A: 

10 seconds to think about it
2 minutes to write it down

hasen j
A: 

I thought this was fun and wrote mine in a little under four minutes from firing up Visual Studio to running the final executable. No unit tests though, so I can't prove that it's all working okay.

In c#, I wrote:

        for (int count = 1; count <= 100; count++)
        {
            bool isMod5 = count % 5 == 0;
            bool isMod3 = count % 3 == 0;

            if (isMod3 || isMod5)
            {
                Console.WriteLine((isMod3 ? "Fizz" : "") + (isMod5 ? "Buzz" : ""));
            }
            else
            {
                Console.WriteLine(count.ToString());
            }
        }

And even though it's fairly simple, I think it'd be interesting to see how somebody goes about explaining their thinking - or even watching them write it - seeing what sort of refactoring they do as they go.

Definitely a valid interview question. But getting them to look over some production code and spot the mistakes is good too!

davewasthere
+1  A: 

I took JustJeff's answer and ran with it, in java. I tried to keep up with his demands (except for TPS, er, reports). This should give you the flexibility necessary to change either the divisors or the loop start/end variables.

Note that I left in some helper text so you can see what number is being checked for fizzbuzz-ability.

public class FizzBuzz {

 static final int FIZZ_DIVISOR = 3;
 static final int BUZZ_DIVISOR = 5;

 static final String FIZZ = "Fizz";
 static final String BUZZ = "Buzz";
 static final String FIZZBUZZ = "FizzBuzz";

 static final int MIN = 1;
 static final int MAX = 100;

public static void main(String[] args) {
    for(int i=MIN;i <= MAX; i++) {

        if (isFizzy(i) && isBuzzy(i)) {
            System.out.println("i" + i + ": " + FIZZBUZZ);
        } else
        {
            if (isFizzy(i)) {
                System.out.println("i" + i + ": " + FIZZ);
            }
            else if (isBuzzy(i)) {
                System.out.println("i" + i + ": " + BUZZ);
            }
        }
    }
}
private static boolean isFizzy(int i) {
    return (i % FIZZ_DIVISOR == 0) ? true : false;
}
private static boolean isBuzzy(int i) {
    return (i % BUZZ_DIVISOR == 0) ? true : false;
}

}

Tony R
The client now wants to print FIZZ instead of BUZZ and viceversa. I'm looking forward to see the confusing result.
ASalazar
A: 

$a = 1; $mod3 = 3; $mod5 = 5;

while ($a <= 100){

if (($a%$mod5 == 0)&&($a%$mod3 == 0)){ echo 'FizzBuzz
'; }

    elseif (($a%$mod3 == 0) && ($a%$mod5 != 0)){
echo 'Fizz <br />';

}elseif (($a%$mod5 == 0)&&($a%$mod3 != 0)){ echo 'Buzz
' ; } else{ echo $a . '
';} $a++; }

simple PHP If structure variation..

5 - 10 minutes max...

swiftDPI
A: 

Don't think it's so easy being a senior developer.

I used a variable to store each printed text, just in case it was going to be used by the caller. Also, as I keyed it I was wondering if it was OK to use hardcoded values and if the range, divisors and substitute strings should be flexible.

The output variable stayed and the other considerations were put on the draft for version 2.0.

Even with just the output variable my code looked slightly uglier than the more straightforward versions, sigh.

ASalazar