FizzBuzz: One Simple Interview Question

  • Published on: 31 July 2017
  • There are a lot of opinions on how to hire coders, and most of them are terrible. The opinions, that is, not the coders. But a basic filter test to make sure someone can do what they say they can: that seems reasonable, and FizzBuzz is one of the more common tests. Even now, interviewers use it. Let's talk about why it's tricky, and how to solve it.

    Imran's blog post:

    Other approaches for pretty much every language:

    Thanks to the Cambridge Centre for Computing History:

    The thing behind me is their Megaprocessor:

    And thanks to my proofreading team!

    I'm at
    on Twitter at
    on Facebook at
    and on Snapchat and Instagram as tomscottgo
  • Runtime : 7:18
  • tom scott tomscott the basics computer science fizzbuzz interview interview question fizzbuzz test comp sci javascript


  • Nico Braun
    Nico Braun   23 hours ago

    The letter i stands usually for 'index' in this context. It makes obviously more sense if it's used to access enumerable like arrays.

  • Sandro Schaier
    Sandro Schaier   1 days ago

    Is it just me or does someone else really hate to append strings if it is not necessary.

  • paddy
    paddy   1 days ago

    I think i is for integer

  • MsJavaWolf
    MsJavaWolf   2 days ago

    there is no "thinking forward" in fizzbuzz, I am sorry but if you can't solve this in your sleep you are not a programmeryou might be many things, you might be a great person, but the correct way to do it is so obvious to any programmer

  • jzeman
    jzeman   2 days ago

    More important than coding is understanding fundamental principles of software architecture: design patterns, clean code, test driven code, etc. I am shocked to still find that some universities do not even teach the gang of four design patterns. Anyone can code, few code beautifully.

  • Baritone Beard
    Baritone Beard   4 days ago

    2:52I believe programmers use 'i' as a relic to the days of Fortran programming, where variable names had specific purposes. I,J, and K were iterators.I believe.I could be mis-remembering some of that info but thats the gist im sure somebody will correct it

  • Sparrow
    Sparrow   4 days ago

    I for Iterator, when iterating over a collection.

  • Jason L
    Jason L   5 days ago

    Should use stringbuilder, way more efficient

  • baabaa9000
    baabaa9000   1 weeks ago

    What kind of programming job is so simple that anyone who can program this exercise can do it? This is not exactly a complicated exercise.

  • Kip
    Kip   1 weeks ago

    My probably very bad but easilly expandable solution to this in java with processing:int currentNumber;int[] dividers = {3,5,7,8};String[] messages = {"Fizz", "Buzz", "Fuzz", "Bizz"};String output;void setup(){ for (int i = 0; i < 101; i++){ output = ""; for (int j = 0; j < dividers.length; j++){ if (i % dividers[j] == 0 && i != 0){ output += messages[j]; } if (j == dividers.length - 1 && output == ""){ output = str(i); } } println(output); } }

  • Peter Schorn
    Peter Schorn   1 weeks ago

    This challenge is way to easy. I don't see how it helps you hire competent programmers.

  • efenty FNT
    efenty FNT   1 weeks ago

    i came up with this:length = 100 x = [3,5] xans = ["fizz","buzz"] for i in range(0, length): word = ""; for n in range(1, len(x)): if i % x[n] == 0: word = word + str(xans[n]); if word == "": print(i); else: print(word);

  • TotalStorm 3.0
    TotalStorm 3.0   1 weeks ago

    I was so surprised. I can do this in 3 languages and I’m 13. Does that mean I could get a job as a programmer?

  • Space Volvox
    Space Volvox   1 weeks ago

    this is the java format of itfor(int i = 1; i <= 100; i++) { System.out.println(""); if(i % 3 == 0) { System.out.print("fizz"); } if(i % 5 == 0) { System.out.print("buzz"); } if(i % 3 != 0 && i % 5 !=0) { System.out.print(i); } }

  • Amazed Alloy
    Amazed Alloy   1 weeks ago

    It's basically just1. Loop2. Check if both. If yes, print fizzbuzz3. Check 3 and not 5. If yes, print fizz4. Check 5 and not 3. If yes, print buzz5. If none, print the number6. Add one to the number

  • Wolf Elkan
    Wolf Elkan   1 weeks ago

    6:191, 2, Fizz, 4, Buzz, Fizz, Fuzz, 8, Fizz, Buzz, Bizz, Fizz, Biff, Fuzz, FizzBuzz, 16, 17, Fizz, 19, Buzz, FizzFuzz, Bizz, 23, Fizz, Buzz, Biff, Fizz, Fuzz, 29, FizzBuzz, 31, 32, FizzBizz, 34, BuzzFuzz, Fizz, 37, 38, FizzBiff, Buzz...

  • Zeldagigafan
    Zeldagigafan   2 weeks ago

    This, and Fibonacci with overflow detection is something that should be practiced everywhere in the hiring process.

  • Chris Singleton
    Chris Singleton   2 weeks ago

    I'm the complete opposite, give me a problem to solve and I'll get it done. Ask me a theory question and I'm a blubbering mess...

  • BiskviLover 3096
    BiskviLover 3096   2 weeks ago

    Can someone explain to me how "if i / 3 = 0, then blah blah blah" works out if i is a multiple of 3? Wouldn't that only work when i is 0?

  • Brendan McCabe
    Brendan McCabe   2 weeks ago

    I would just do if i=3,6,9,12.......and then if i=5,10.....and if i=15,30,45......

  • Rushil Jalal
    Rushil Jalal   2 weeks ago

    Tom: Programing fizzbuzz is a test for identifying a good programmerMe: Able to program FizzBuzz Also me: How is this possible?

  • Void Venom
    Void Venom   2 weeks ago

    2:51 - I've always told myself that it is "i" for "iteration".

  • 9rh9
    9rh9   2 weeks ago

    My python oneliner:print("".join(("".join(extention for dividor, extention in {3: 'fizz', 5: 'buzz'}.items() if x % dividor == 0)) + '\n' if len(("".join(extention for dividor, extention in {3: 'fizz', 5: 'buzz'}.items() if x % dividor == 0))) > 0 else str(x) + '\n' for x in range(1, 101)))more comprehensive solution where a future programmer might actually understand and expand: tests = {3: 'fizz', 5: 'buzz'} for x in range(1, 101): output = '' hit = False for dividor, extention in tests.items(): if x % dividor == 0: output += extention hit = True print(output if hit else x)

  • Jeffrey Kiska
    Jeffrey Kiska   2 weeks ago

    I didn't scroll through all 4000+ comments to see for sure, but it (unsurprisingly) doesn't look like my language of choice is very common among this audience.1..100 | %{ $o=""; if ($_%3 -eq 0) { $o += "Fizz" }; if ($_%5 -eq 0) { $o+="Buzz" }; if (-not($o)) { $o=$_ }; $o }

  • antipoti
    antipoti   2 weeks ago

    'i' stands for 'index' -> mind = blown

  • Salman Hasan
    Salman Hasan   2 weeks ago

    for (number = 1; number <= 100; number ++) { if (number % 3 == 0){ console.log("Fizz"); }else if (number % 5 == 0){ console.log("Buzz"); }else if (number % 3 == 0 && number % 5 ==0){ console.log("FizzBuzz"); }else { console.log(number); } would that work?

  • Rohan1078
    Rohan1078   3 weeks ago

    I thought my computer science teacher made fizz buzz up, I managed to do it in python, computer science job please 😀

  • NateROCKS112
    NateROCKS112   3 weeks ago

    2:51 I believe programmers use i to stand for "integer," because it's a throwaway variable and generally integer or int is a keyword. They also use s for string or c for character, iirc

  • Mark Stoddard
    Mark Stoddard   3 weeks ago

    Write the whole thing as a string, print the string. No reason to waste time doing ANY math

  • Jared Householder
    Jared Householder   3 weeks ago

    His final fizzbuzz solution was my exact answer! Same language too!

  • Lukeff7
    Lukeff7   4 weeks ago


  • Jared Mundt
    Jared Mundt   4 weeks ago

    That's so easy. How could you get a CS degree without being able to some basic else if statements?

  • nfcopier1
    nfcopier1   4 weeks ago

    A somewhat different and odd way:```for(let n = 1; n <= 100; n++) console.log(fizz(n));function fizz(n) { const isThreeDivisible = n % 3 === 0; const isFiveDivisible = n % 5 === 0; if (isThreeDivisible && isFiveDivisible) return "FizzBuzz"; if (isThreeDivisible) return "Fizz"; if (isFiveDivisible) return "Buzz"; return n;}```