Hacker News new | ask | show | jobs
by ckuehne 3720 days ago
How is Fizzbuzz a trick question?
3 comments

Going to echo this sentiment: I think the only way FizzBuzz is a trick question is if you aren't familiar with the modulus operator, in which case I think it fair to say you haven't spent much time programming.

That being said, I'm assuming the failure mode we're discussing is 'flailing at the whiteboard and would never make any progress given infinite time' and not 'wrote an off-by-one error that a unit test would catch.'

Even if you've never heard of the modulus operator, it's still easy, eg in Python:

  fizz = 3
  buzz = 5
  both = 15

  for i in range(1, 101):
      if i == both:
          print "FizzBuzz"
          both += 15
          fizz += 3
          buzz += 5
      elif i == fizz:
          print "Fizz"
          fizz += 3
      elif i == buzz:
          print "Buzz"
          buzz += 5
      else:
          print i
If you can't write your own modulo function if don't understand the fundamentals of integer/floating point operations. Or are unaware of ceil and floor functions.
To someone who can't do it, it is a trick question.

The "trick" is the first hump - a goat.

argumentum ad hominem (edit: was never asked to do Fizzbuzz)
Not at all.

Even a simple programming question can stump someone not trained in it. I've seen people who (supposedly) have computer science degrees fail on FizzBuzz.

In the end, it makes some sense to "talk shop" about programming issues. If they can't follow, it's probably not a good idea to hire them.

From this thread you'll find people that will reject someone with 10 years of experience because of failing Fizzbuzz in the conditions of an interview. It's not always used to talk shop. What I say is that there are things that are probably more statistically significant that questions with gotchas.
So? I've interviewed people with graduate Computer Science degrees who couldn't program a for {...} loop. Blew my mind, but it happened enough times that it doesn't surprise me any more.
Fizzbuzz trick: you have to make a special case for modulo 15, you can't reuse the 3 and 5 cases.

string reversing in place trick: stopping at the middle else it's an identity function.

Any time you spend with Fizzbuzz, you could spend it on more complete quizzes, discussing past experiences, taking references etc.

And if the candidate trips up, this gives you an opportunity to walk through a virtual compile-debug-test cycle.

When I asked these kinds of questions I would execute the program in my head, and tell the candidate things like "your reverse() methods moves some stuff around, but the end result appears the same as before". Or "this fails with ArrayIndexOutOfBounds on line X". Typically it only took a few minutes to find the bug and fix it, and I learned about how the candidate solves problems.