14

We had a senior level interview candidate fail a nuance of the FizzBuzz question12.
I mean, really, utterly, completely, failed the question - not even close.
I even coached him through to thinking about using a loop and that 3 and 5 were really worth considering as special cases.

He blew it.

Just for QA purposes, I gave the same exact question to three teammates; gave them 5 minutes; and then came back to collect their pseudo-code. All of them nailed it and hadn't seen the question before. Two asked what the trick was...

On a different logic exercise, the candidate showed some understanding of some of the features available within the language he chose to use (C#). So it's not as if he had never written a line of code. But his logic still stunk.

My question is whether or not I should have given him the answer to the logic questions.

He knew he blew them, and acknowledged it later in the interview.
On the other hand, he never asked for the answer or what I was expecting to see.

I know coding exercises can be used to set candidates up for failure (again, see second link from above). And I really tried to help him home in on answering the core of the question. But this was a senior level candidate and Fizz-Buzz is, frankly, ridiculously easy even after accounting for interview jitters.

I felt like I should have shown him a way of solving the problem so that he could at least learn from the experience. But again, he didn't ask.

What's the right way to handle that situation?


1Okay, that's not the link to the actual FizzBuzz question, but it is a good P.SE discussion around FizzBuzz and links to the various aspects of it.

2 To help clarify, this is the nuance of Fizz-Buzz I asked and it's from Project Euler's first problem. Substitute printing Fizz | Buzz for summing the numbers and you have the same fundamental question.
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Write a function that finds the sum of all the multiples of 3 or 5 below 1000.

3 This question attracted more attention than I had expected, and I appreciate all of the replies. Some of the later answers have really gotten to the core of my question, so I'll allow the community to review and up-vote before assigning "the" answer.

4 I selected "the" answer based upon community votes at that point in time. And I think Yannis' answer is appropriate for interviews with newer devs. I think the collective response focusing on the lack of asking for the answer is spot-on as well.

  • They can walk out of the interview and google the answer to every single question they missed, so you're not giving them anythnig they can't get by giving them the answer, though in their response to the answer you might learn something of them. Though fizzbuzz failure on senior doesn't even matter, they are so far off in assessing their skills or outright lying, I don't know that it makes any difference whatsoever. – Jimmy Hoffa Nov 14 '12 at 05:02
  • 34
    Cut 'em loose and get on with your day. As far as I'm concerned, failing FizzBuzz at the "senior level" is purposely and maliciously wasting my time. – Steven Evers Nov 14 '12 at 06:19
  • 6
    I recently interviewed for several positions in my area, and the ones that required code indicated to me that they were having trouble finding senior level candidates who could pass their own "FizzBuzz"-ish tests. In every case my reaction was "you can't be serious". There are apparently a lot of terrible programmers out there masquerading as senior level who aren't even close. – Joel Etherton Nov 14 '12 at 13:59
  • 6
    @JoelEtherton - Same thing around here. I've pushed for phone screens everywhere I go. If you're applying to be a Senior using C# and can't tell us the difference between a value type and a reference type, you're not getting an interview. – Telastyn Nov 14 '12 at 14:18
  • 1
    I wouldn't consider someone Senior until they have led a team. Just because you have been a software programmer for 30 years, does not make you senior. Just someone who has been doing a job for 30 years, nor does it make you necessarily good at it. – Engineer2021 Nov 14 '12 at 14:19
  • @Telastyn: Apparently the problem in my area is that a lot can talk a good game and have studied reference materials so they can provide definitions, but when it comes to problem solving, logic application, algorithm design they just don't have the experience. – Joel Etherton Nov 14 '12 at 14:21
  • @Telastyn Gah, I hate that. The guy who wrote most of our codebase overrode all of the == and != operators in our custom classes to check for value equality instead of reference. It's such a pain. (Edit: 'at'ed the wrong person) – KChaloux Nov 14 '12 at 14:39
  • @JoelEtherton - Yeah, there's plenty of those guys too but they're at least worth the interview to test program design. A non-technical person can give the basic phone screen. – Telastyn Nov 14 '12 at 14:47
  • @Telastyn one of my first phone screen questions is "what's the difference between using the struct and class keywords in C#?" I've yet to come across a candidate who can't answer that and pass the phone screen. – Michael Brown Nov 14 '12 at 15:12
  • 3
    @0A0D, leading a team is a different *kind* of skill from being a good developer. I've seen team leads who were bad developers too. – Kyralessa Nov 14 '12 at 16:07
  • @Kyralessa: Yes, it is a different skill but you can't expect to call yourself Senior due to the number of years under your belt. You better either be 1. a good developer and leader, or 2. an expert developer. – Engineer2021 Nov 14 '12 at 16:11
  • 4
    @JoelEtherton, don't act surprised. I thought "199 out of 200 applicants can't code" was mere hyperbole until I actually started helping screen and interview candidates. Years of (alleged) experience simply do not matter. Job titles do not matter. Most applicants are indeed incredibly junior, whether they know it or not. – Anthony Pegram Nov 14 '12 at 20:45
  • 2
    That sum-the-multiples problem isn't really the same as fizz-buzz. You *could* use a fizz-buzz-like solution, but the easiest way to to loop to sum the multiples of 3, then loop to add on the multiples of 5, then loop again to subtract the multiples of 15 you double-counted in the first two loops. A *clever* approach would use the [triangular numbers](http://en.wikipedia.org/wiki/Triangular_number) to get rid of the loops altogether, since each loop gives a multiple (by 3, 5 or 15) of a triangular number. –  Nov 15 '12 at 01:47
  • @Steve314 - _that_ approach would have cleared the test; even if it wasn't coded out fully. Props for the reference to triangular numbers. –  Nov 15 '12 at 20:58

9 Answers9

15

Most of my interviews were with students looking for an internship position, and more often than not they screwed up simple (?) exercises. I wanted an easy and friendly way to communicate their errors, and what I came up with was quite simple: I solved the exercises myself, and showed them my solutions after they finished with theirs.

I had quite a few extremely interesting and revealing discussions with candidates that started by comparing our different approaches to solving the same problem. After a while I even anticipated some of the errors, just by checking which school the candidate was attending (some "professors" are... morons). And, well, in the few instances that a candidate couldn't come up with any solution, I had already given them one for next time.

yannis
  • 39,547
  • 40
  • 183
  • 216
  • Makes sense; I was looking for a new job recently, and I found that most interviewers did this same thing when I gave wrong answers (or slightly "off the point answers") to their questions. This is a really good practice. Mostly because it opens up the candidate (me eg.) and makes the interview itself more engaging from both sides. But of course, we were discussing templates, RAII and multithreading in C++. The question is what do you say to a person who cant solve fizzbuzz ? – Chani Nov 14 '12 at 05:38
  • 11
    @RitwikG Honestly, if the candidate is interviewing for a programming position and can't cope with fizzbuzz, I'd probably... laugh (hey, I never said I was a _good_ interviewer ;). That said, a few months back I lost about a couple of days fighting what turned to be an _extremely_ trivial [OBOE](http://en.wikipedia.org/wiki/Off-by-one_error) in my code. We all have our off moments, and I wouldn't really fixate on the candidate messing up one exercise, I'd probably move on to the next one quickly. If they failed the next one as well, I'd probably thank them for their time and move on. – yannis Nov 14 '12 at 05:46
  • 1
    @YannisRizos That's probably a good approach; there's always a chance that the person doesn't do well in interview situations, or has somehow avoided the modulo operation in their work (although that doesn't bode well, to say the least). In my experience, a significant number of applicants are stumped when asked to write any simple loop (in any language of their choice), even for senior positions. Now *that*, I find completely impossible to justify. – Daniel B Nov 14 '12 at 09:57
  • That's some good insight into the process as well. The candidate was understandably nervous, and I was more than willing to give some allowance for that. When he finally started talking through his attempt at a solution, it was just convoluted and created boundary conditions that he missed. –  Nov 14 '12 at 15:25
15

Giving the Answer

I was going to say that if the candidate isn't interested enough to ask, I wouldn't waste my breath, but @Yannis_Rizos answer is much better.

Interviews are pretty fast paced. I know I often look things up for days after an interview.

People Who Can't Code FizzBuzz Classic

I imagine a big sticking point is being aware of the % operator. You would hope that someone could think to compare (myInt / 3) == (myDouble / 3.0) but maybe with the stress of an interview... Still, FizzBuzz Classic forces a brute-force approach, putting it in the category of the easiest algorithm problems to solve. As a hint, have you tried asking people to just code "Fizz" for half-credit and maybe add "Buzz" later as an enhancement?

I think the ultimate answer to your question is that it's just really hard to find good candidates.

Interview Questions in General

I've often found it easier and more productive to ask candidates to describe the last programming project that they were excited about. I've had 100% success with this question, meaning that people who spoke animatedly about a programming project and could answer technical questions about it were great hires and those who couldn't, weren't. This has the nice side effects of putting the candidate at ease, and encouraging open-ended discussion. With this question, the candidate will, in effect, tell you what they are most suited for.

Maybe at a think tank algorithm questions are necessary as well, but I've abandoned them in favor of the "favorite project" question.

Sum (Son) of FizzBuzz

Your interview question is not equivalent to FizzBuzz:

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23. Write a function that finds the sum of all the multiples of 3 or 5 below 1000.

Where FizzBuzz Classic forces you to go through n iterations (to print out every number or Fizz/Buzz), your problem can be done in n/5 + n/3 + n/15 iterations, or even no iterations - a direct fixed-point calculation is possible. The following program compares these three methods:

public static void main(String[] args) {
  long n = Long.valueOf(args[0]).longValue();
  long sum = 0;
  long ms = System.currentTimeMillis();
  // Brute force method  Performance: cn
  for (long i = 1; i <= n; i++) {
    if ((i % 3) == 0) { sum += i;
    } else if ((i % 5) == 0) { sum += i; }
  }
  System.out.print("Brute force sum:    " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
  ms = System.currentTimeMillis();

  // Second solution: iterate through only numbers we are
  // interested in.  Performance: c * (n/3 + n/5 + n/15)
  // We counted multiples of 15 twice, so subtract one of them
  sum = countSum(n, 3) + countSum(n, 5) - countSum(n, 15);
  System.out.print("Only multiples sum: " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
  ms = System.currentTimeMillis();

  // Third solution: Use high school algebra.  Performance: c
  sum = sumSeries(n, 3) + sumSeries(n, 5) - sumSeries(n, 15);
  System.out.print("Sum of series:      " + sum);
  System.out.println(" time: " + (System.currentTimeMillis() - ms));
}

// Iteravely sum all multiples of skip
private static long countSum(long n, long skip) {
  long skipTotal = skip;
  long grandTotal = 0;
  while (skipTotal <= n) {
    grandTotal += skipTotal; skipTotal += skip;
  }
  return grandTotal;
}

// Thanks to @Caleb for pointing this out!  High school algebra
// tells us that the sum of a series is: (n * (a1 + an)) / 2
// where a1 is the first term and an is the nth term.  E.g. The
// sum of a series of 3 is: (n/3 * (3 + n - (n % 3))) / 2
// Since we are thinking about performance here, we'll shift
// right one instead of dividing by 2 for style points.  ;-D
private static long sumSeries(long n, long skip) {
  return (n/skip * (skip + n - (n % skip))) >> 1;
}

Output (sum of FizzBuzz < 1000):

$JDK_HOME/bin/java FizzBuzzNot 999
Brute force sum:    233168 time: 0
Only multiples sum: 233168 time: 0
Sum of series:      233168 time: 0

With a larger n for performance comparison:

$JDK_HOME/bin/java FizzBuzzNot 1000000000
Brute force sum:    233333334166666668 time: 4744
Only multiples sum: 233333334166666668 time: 818
Sum of series:      233333334166666668 time: 0

Note to those who down-voted this as off-topic

The point of presenting a solution to this question is to show that while the brute force solution to Sum of FizzBuzz is similar to FizzBuzz Classic, better solutions to the Sum problem are available, making it a fundamentally different problem. Sum of FizzBuzz is extremely tricky if you don't remember the proper formula for the sum of a series, or don't realize that it applies when stepping by 3 or 5.

If you re-derive the formula for the sum of a series by splitting the series in half, reversing one half, and pairing them up, you get (n + 1)(n / 2) which can take you down a really messy path as far as integer division and truncated remainders are concerned. The (n(a1 + an)) / 2 version of this formula is absolutely critical for a simple answer for all values of n.

GlenPeterson
  • 14,890
  • 6
  • 47
  • 75
  • 3
    This can be calculated directly (Ruby): `t = { |i| (i * (i+1)) / 2 }; fizzbuzz = { |n| 3 * t((n-1)/3) + 5 * t((n-1)/5) }` – kevin cline Nov 14 '12 at 20:56
  • 3
    http://www.codinghorror.com/blog/2007/02/fizzbuzz-the-programmers-stairway-to-heaven.html – DHall Nov 14 '12 at 21:20
  • @DHall Heh heh, true! Glen's answer is awfully off-topic, but is a fine example of this irresistible urge all programmers have :) – Andres F. Nov 14 '12 at 21:36
  • 1
    @GlenH7 Yeah, I deleted my comment because it was buzzkill. Glen deserves props for his analysis, even if it doesn't answer the question AT ALL :D (Besides, I totally coded and tried my own solution moments ago) – Andres F. Nov 14 '12 at 21:40
  • 1
    @GlenPeterson - we have more interesting questions too. But the fact that you killed an hour on finding a more efficient solution was kind of a giveaway.... –  Nov 14 '12 at 22:01
  • 1
    Is the solution to this problem supposed to double count numbers that are multiples both of 5 and 3? – Mike Nov 15 '12 at 04:29
  • 2
    You are looking for a sum of a series, given that this series is of modulo=0, the formula n/2*(m+nm) can be used. Where m=the modulo number and n=number of elements in the series (aka floor(x/m). After that it's easy, S(3) + S(5) - S(3*5) [so that some numbers don't get counted twice]. – jmoreno Nov 15 '12 at 07:42
  • 3
    One reason you might be having a problem, is that you are counting some numbers twice (those divisible by 15). For an example program see http://ideone.com/clone/oNWrhJ – jmoreno Nov 15 '12 at 08:51
  • 1
    @GlenPeterson Do you know how to sum consecutive integers 1..n? You ad the first and last, second and second last, etc. Write that out and you'll see that each pair is equal to (n+1). Since there are n numbers altogether and each pair uses 2 numbers, the total is (n+1)(n/2). Kevin Cline's solution (and mine) uses the same idea, just multiplied to count only every 3rd or 5th integer. For example, the sum of multiples of 3 between 1 and 20 is (3+18)(20/3)/2 = 21*6/2 = 63. – Caleb Nov 15 '12 at 18:50
  • I would plus 1 again if I could for the effort you've put into the answer. OTOH, you hit Wiki status, so I don't know that it would do any good. Note for future readers: many of the comments in this answer won't make sense unless you align the comments with the answer revisions by their timestamps. –  Nov 15 '12 at 21:03
  • this can be done without a single iteration. i will post my code in another answer – amphibient Nov 15 '12 at 22:02
  • You're saying fuzzbuzz2 is harder, but you've also changed the goalposts quite a bit. – whatsisname Nov 16 '12 at 05:45
8

I felt like I should have shown him a way of solving the problem so that he could at least learn from the experience. But again, he didn't ask. What's the right way to handle that situation?

I don't care what level the interview is for, nor even really if its a "FizzBuzz"-level question or an advanced question. If you ask a candidate to solve a question, and they can't, but don't even bother asking you for the right answer then they aren't worth your time. How in the world could you be so intellectually lazy?!?

And even if you totally stink as a programmer and are just trying to buffalo your way into a job, why wouldn't you at least be so pragmatic as to get the right answer now, so that you know it for the next interview?

So no, you shouldn't "give" the answer, but you should expect to have the candidate insist on hearing the right answer after they fail. If they don't, its a huge red flag in my book.

If someone blew FizzBuzz in a junior level Dev interview because they couldn't remember the modulus operator and just couldn't bring themselves to move on without it, but they then got all passionate about re-doing it once you explained the right answer, or at least talking through the right code with you, then that's almost as good as answering it correctly.

Graham
  • 3,833
  • 1
  • 21
  • 18
  • 1
    Why? You can just Google the answer later. FizzBuzz is pretty popular. I'd be honestly concerned if someone does not know modulus division. – Engineer2021 Nov 14 '12 at 14:18
  • I would have given him credit for trying to come up with something instead of the modulus operator, but he didn't even get to that point. I think you have a good point with focusing on his failure to ask for the answer. Your observation is in line with some of the other challenges that came up during the interview. –  Nov 14 '12 at 15:18
  • I get really opinionated about FizzBuzz...but this is the right answer. If the candidate doesn't ask for the answer, don't give it to them. – James P. Wright Nov 14 '12 at 15:34
  • @JamesP.Wright - I agree to some degree, and going into the interview, I was a bit embarrassed to use that as the lead coding question. It was _supposed_ to be ridiculously easy, and I even prefaced it with a warning to not over-read the question. I had a follow-up that was also supposed to be easy, and then I had a third that would allow him to demonstrate higher level development / design skills. We never got to the third question.... –  Nov 14 '12 at 15:43
  • @GlenH7 - See that's the reason I always have a problem with FizzBuzz. I'm bad at math. I didn't know the Modulus operator until a few years ago when FizzBuzz became all the "buzz". I had absolutely no clue how to complete FizzBuzz, but I'd been programming for over 10 years. Absolutely nothing in my entire career had ever needed to use anything like it. Once I knew about modulus I figured out how to do FizzBuzz in 5 minutes, but my lack of ability to do it didn't really say what I COULD do, but what I already knew how to do. (continued in next comment...) – James P. Wright Nov 14 '12 at 16:12
  • Now, if the job this person was interviewing for required them to do math and complex algorithms, that's fine...FizzBuzz away. However, I've had interviews for "senior" developer positions that were absolutely nothing more than "Gather requirements from client, make a website that pulls data from a database and saves data to a database." and they asked questions like FizzBuzz because someone told them it was important. THAT is where I get annoyed with it. Ask questions that are relevant to the position you are hiring for, not what you THINK makes someone a senior developer. – James P. Wright Nov 14 '12 at 16:14
  • @JamesP.Wright: That's because programming has been dominated lately by computer scientists and software engineers who typically will have a background in Math and Science, so they will be exposed to these sorts of things. For the reference, you can implement modulo like this: x-((x/n)*n) – Engineer2021 Nov 14 '12 at 16:16
  • FizzBuzz does not require the modulus operator. It simply requires code to check and see if an int is evenly divisible by 3 or 5. This could be accomplished by casting to double and looking for results with decimal values. I wouldn't really fault a programmer for not knowing the modulus operator in a given language, as I can't recall a case where I've used it recently at all, but I CAN fault a dev for not even trying to think through the problem somehow. – Graham Nov 14 '12 at 16:16
  • @Graham : I agree. I'd say the key in this situation isn't that the "senior dev" candidate couldn't do FizzBuzz, it's that he could even begin to work it out enough to satisfy GlenH7. I guess it just bothers me that so many people out there who have gone through college for a CS degree are starting to dominate the field and things they consider "the basics" are things a self-taught developer like me haven't used in over a decade of programming. It really feels like we need to make a distinction between "business developers" (folks who make CRUD apps) and "lower level" devs – James P. Wright Nov 14 '12 at 16:21
  • @JamesP.Wright - full disclosure, I (now) work for an Engineering firm. So, yes, Math and complex algorithms _are_ kind of important. As Graham points out, there are other ways to solve without using modulus, and I would have given full credit for those attempts. Heck, he could have even built an array with all the multiples and checked against that. My problem was that he didn't even get close to coming up with a workable approach, which is why I asked what I should have done or told the candidate afterwards. –  Nov 14 '12 at 16:23
  • @JamesP.Wright - FWIW, I'm fine with the self-taught programmer as well. Essentially, that's what I am since my engineer background didn't overlap with formal programming. The candidate's solution tried to use recursion and missed boundary conditions. I strongly hinted at that mistake and he didn't see the error in his logic. –  Nov 14 '12 at 16:26
  • @GlenH7: If the job requires math, then test for it.. otherwise, give a problem that tests the skills you are looking for.. I am just an outsider looking in, but if you gave an unfair test to someone who has never been exposed to this stuff as a practical programmer, then its not really his fault. – Engineer2021 Nov 14 '12 at 16:31
  • It's a sad day when people on programmers.SE are considering the modulus operator "advanced math" or "not necessary for their jobs". Next up: "I don't need to know division or multiplication, I never used them in my web app". – Andres F. Nov 14 '12 at 16:43
  • 1
    @0A0D, the "math" involved in FizzBuzz is simply checking if a given variable is divisible by 3 and/or by 5. That level of math is present in virtually every app you write. Even "business devs" like me who just implement the same kind of projects over and over use this level of math. GlenH7, I'm not even sure if using recursion in FizzBuzz would impress me or scare me off.... Certainly seems like dangerous overkill. – Graham Nov 14 '12 at 16:49
  • @Graham: I guess. I am working on some WSDL and other GWT stuff.. no math :) But when I have done geospatial work, heavy on the math.. so it all depends. – Engineer2021 Nov 14 '12 at 16:51
  • 'So no, you shouldn't "give" the answer, but you should expect to have the candidate insist on hearing the right answer after they fail. If they don't, its a huge red flag in my book.' See, I read that as "If they don't have complete disrespect for my time, it's a huge red flag". Some people follow the idea that you don't waste other people's time. I wouldn't ask because I was there for an interview, not to learn methodologies. Is this wrong? Maybe. But to find out that respecting other people and their time is a red flag? Concerning. – Aeo Nov 16 '12 at 16:34
  • What you call a "waste other people's time", I call "demonstrating your ability". Rarely did a time limit for an interview become a factor for me as an interviewer. You've got an hour to convince me you don't suck, so what do you want to show? If its jam-packed, then maybe yeah, don't harp on a missed question, but if you have 2-5min to spare, asking to see the correct answer demonstrates SOME kind of curiosity, as opposed to "giving up", because that's EXACTLY how I viewed people who didn't ask for the answer after failing a question. – Graham Nov 16 '12 at 18:48
4

I typed out fizzbuzz while on the phone with the interviewer during a pre-screen. That's something that, even if everyone hasn't heard of, you should be able to cobble together after a semester of course work but definitely after acquiring "senior" status.

There's really no recovery from not being able to do that. It's one of those necessary nuisances that you need to get out of the way just in case.

I would say that it makes sense to deliver as a pre-screen so you're not wasting everyone's time with bringing them on site for an interview.

Michael Brown
  • 21,684
  • 3
  • 46
  • 83
  • For our pre-screen, we had asked for some sample code, which was provided. That code had some intermediate to advanced C# language features, so I really expected him to blow through the logic questions in just a minute or two. –  Nov 14 '12 at 15:20
  • 7
    When the sample code provided does not match demonstrated knowledge in an interview, my brain immediately becomes suspicious of the sample code. – Graham Nov 14 '12 at 16:59
  • @Graham: Hire him as a temp for 6 months.. – Engineer2021 Nov 14 '12 at 18:22
  • @0A0D Sadly I've never worked at a place that allowed that kind of flexibility. If the position advertized was a full time gig, that's ALL we could offer the person. – Graham Nov 14 '12 at 19:43
  • @Graham: Interesting.. it seems like a no-brainer. Usually you get no benefits though. My employer offers it as an option to people they are on the fence about. – Engineer2021 Nov 14 '12 at 20:16
  • 3
    There's no fence in that scenario. If his "sample code" demonstrates a strong knowledge and he can't code fizzbuzz, pull out the sample and ask him specifics. If he can't back it up, then it's time for my favorite line "we still have some candidates to review, we'll get back to you." – Michael Brown Nov 15 '12 at 04:03
  • Yeah I agree with Mike. I once was on an interview team for a mid-level C# candidate. All the right buzzwords and code samples were provided, but the candidate failed on the 1st question: "Show us HelloWorld in C#". – Graham Nov 15 '12 at 13:13
  • @Graham - Been there too. Late last year I did some interviews for a short-term project (short-term for them; I'm still working on that same project, that's just how it goes). Our recruiting firm had "pre-screened" them and were confident my interviews would be a formality. When I asked something out of a Microsoft cert course, like "What are the A-B-C's of WPF", I got the right answer without hesitation. When I set up the shell of a FizzBuzz-like problem on the whiteboard including some simple "unit tests" I expected them to pass, and handed them a dry erase marker, I got blank stares. – KeithS Jun 23 '15 at 19:23
4

I even coached him through to thinking about using a loop and that 3 and 5 were really worth considering as special cases.

It'd be interesting to know what you think the "correct" answer to your FizzBuzz-ish question is. From where I sit, a good one (in C) written to the letter of your question is:

int f(void) {
    // sum the multiples of 3 and of 5 and subtract multiples of 15 so we don't count them twice
    return ((1000/3)/2)*(999+3) + ((1000/5)/2)*(995+5) - ((1000/15)/2)*(990+15);
}

A better one might be:

Why the heck would you write a program to do that when you can calculate it directly?

The point is that there's more than one way to skin a cat, and the fact that the candidate in question didn't immediately start writing for loops and mod operators doesn't mean that he's stupid. If you want to know what the candidate knows, discuss the problem -- find out what he's thinking. If he's stuck or confused, find out where and why. He might lead you to an approach that you never considered.

My question is whether or not I should have given him the answer to the logic questions.

As the interviewer, it's not your place to teach the candidate a lesson. If they really don't know how to write code, there's absolutely no need to embarrass them by dwelling on how much they don't know. If they're interested enough to ask, then by all means feel free to share. Otherwise, finish up the interview, thank them for their time, and move on to the next candidate.

Caleb
  • 38,959
  • 8
  • 94
  • 152
  • +1 for the solid answer in your last paragraph. And you raise a good point in that I should have said "an" answer instead of "the" answer. There are several ways to solve that particular one. As to `discuss the problem`, that element came up with other questions during the interview. Regrettably, the candidate was ... less than forthcoming in replying. I didn't add that aspect into the original question as I was really trying to keep within P.SE guidelines for "good subjective." –  Nov 15 '12 at 04:07
  • 1
    "it's not your place to teach the candidate a lesson" - I disagree. A good programmer is always learning. If they respond to your lesson by acting grateful for learning a new things, then its a sign that they are a good programmer. If they shrug off your lesson, then they are most likely a shitty programmer. – nbv4 Nov 17 '12 at 05:47
  • If I were your interviewer, and you gave me that sort of answer, I'd refer you to a school district in need of algebra teachers. FizzBuzz is about demonstrating a basic knowledge of programming so that the interviewer can move on to questions that will differentiate you from other basically decent programmers. Your answers are clever, but they don't establish that you understand looping, modular arithmetic, etc., leaving the interview to either move forward under the assumption that people who know algebra also know programming (wrong), or to simply shake your hand and move on (more likely). – user1172763 Dec 05 '14 at 18:17
  • @user1172763 That's the point -- unlike FizzBuzz, the OP's interview question can be answered with a single calculation. It is therefore a poor choice if the point is to see whether the candidate can write a loop. You can't expect a candidate to choose a slower, far more verbose solution on the assumption that you're asking the question for a specific (and unstated) reason. Indeed, the interviewer could easily be a "trick" question to see if the candidate notices that looping is completely unnecessary. Reading your mind is not the candidate's responsibility. – Caleb Dec 15 '14 at 20:32
2

To answer your question, no I would not give the answer. If the person wants to be a better software engineer, they will find the answer. If you give them answer you are robbing them of this opportunity.

The more relevant question is when can you call yourself a senior developer? This varies between organizations and countries. For example, a company I worked with considered Software Engineers with 5 years of experience as seniors. There was no emphasis on the quality of the experience, just the length.

Until we come up with a standard that will categorize all Software Engineers regardless of their language we are left with the individual deciding the level of their skills. And we will continue hearing of "Senior Engineers" failing the most rudimentary skills test.

A couple weeks ago the question was asked "When should you call yourself a Senior Developer". I also wrote a blog post on the topic.

Chuck Conway
  • 700
  • 1
  • 9
  • 14
2

Your "problem" is that you're an empathetic human, so it's hard to watch someone struggle with a problem that you know the answer to (this is also a problem if you run usability studies). From a duties-as-an-interviewer perspective, you are not in any way obliged to teach the interviewee how to program or problem-solve, or the solution to a problem that you ask.

When you coach an interviewee, it's not so that they can get the right answer. It's so that you can see if they really can't solve the problem or if they just got hung up on one or two mistakes or misunderstandings.

So if you want to give an interviewee the solution after the fact, you're doing it purely for yourself. In general, I'd rather use that time to allow the interviewee attempt another problem. But a "senior" programmer who can't answer FizzBuzz is probably off the list. If you decide to give solutions make sure you don't fool yourself into thinking the interview went better than it did (if you find yourself thinking, "he could not solve the problem, but when I explained it he understood it well", then you're on a dangerous path).

And yes, I have been an interviewee who was in over his head and couldn't even make the first attempt at solving an interview problem. That simply meant that I needed to learn a lot more in order to pursue a job in that field.

Tom Panning
  • 365
  • 1
  • 4
2

Getting the right answer is not the important part of this test. What you're measuring is someone's approach to problem solving, how they engage with the question, anything creative or interesting they come up with along the way; that kind of stuff. Even if they get the wrong answer they may still be viable by these criteria.

OK, not knowing the mod operator is inexcusable, and by the metrics I've given this candidate appears to still be a write-off, but I don't believe that just giving the right answer to this candidate is going to be of any benefit.

This comes down to your own personal opinion from here. Do you want to give interview feedback with a view to helping the candidate do better in future interviews (and so that future interviewers don't have to suffer what you've just gone through)? If so, couch your feedback in the terms I've just outlined above: tell them that it's not just about the right answer but how they work to arrive at the answer is a critical factor.

Maximus Minimus
  • 1,498
  • 10
  • 11
  • +1 for the comment of `how they work to arrive at the answer is a critical factor.` While I expected a modulus operator to be used, that's only because that's how _I_ would have solved it. I was very open to seeing any other approach that solved the problem without creating glaring boundary condition errors (see my various comments about the approach with recursion....). –  Nov 15 '12 at 04:10
2

I felt like I should have shown him a way of solving the problem so that he could at least learn from the experience. But again, he didn't ask. What's the right way to handle that situation?

The way I see it, there is no situation to handle. Assuming that you have rejected his application, the candidate's (apparent) lack of interest is not something you need to concern yourself about.

Indeed, even if he did ask, you don't owe him an explanation. And if you talked to your HR folks about it, they might advise you that further discussions with the candidate is inadvisable for legal reasons.


It is also worth noting that the FizzBuzz problem has different "best" answers depending on how you ask it. If you ask for the "simplest" solution and the "most efficient" solution, the best answers are radically different. And this can colour your judgement unfairly ... if you were unclear in the way that you asked the question. (On the other hand, a good / experienced candidate would have the foresight to clarify that before starting to code ...)

Stephen C
  • 25,180
  • 6
  • 64
  • 87