7 ms·
FizzBuzz Still Works
- TamDenholm 14y agoI'm amazed this still works. Like the author i would've thought everyone going for such a job would instantly know what fizzbuzz is and make sure they know it. Another question i feel works really well in interviews is asking them to show you something they've created, personally or professionally. Its a nice open ended question, gets them talking about something they know and lets you ask many follow up questions about specific parts of the thing they've done which gives you a good feel of what they're capable of.
- ConstantineXVI 14y agoI've wanted to cook up an outlandish solution like this one[0]; but I haven't been confronted with FizzBuzz enough to know I'd ever be able to use it. [0] http://experthuman.com/programming-with-nothing http://experthuman.com/programming-with-nothing
- kbd 14y ago"i would've thought everyone going for such a job would instantly know what fizzbuzz is and make sure they know it." The point of FizzBuzz is that it's not something you "know" or need to study. It's such a trivial problem that any developer should be able to write it off the cuff.
- dllthomas 14y agoYes, but those who can't could cheat by studying it, and with everybody talking about it...
- raganwald 14y agoOne of the things I've learned is that almost all introductory blog posts are wasted: The people I'd most like to reach don't read programming blogs, Hacker News, progreasmming.reddit.com, or anything else. FizzBuzz is famous, but alas it is famous amongst people who could code it without advance knowledge of it.
- pilsetnieks 14y agoFrankly speaking, would you want such a person working for you if they couldn't loop over a list of numbers and write simple arithmetic without advance preparations?
- nathan_long 14y ago>> FizzBuzz is famous, but alas it is famous amongst people who could code it without advance knowledge of it. If that's true, it's still a good screening test. You either have heard of it but could code it even if you hadn't, so you pass, or you haven't heard of it and couldn't code it even if you had, so you fail.
- mark-r 14y agoThe kind of person who has heard of FizzBuzz before is someone who cares about their profession and reads about it. They're unlikely to fail the test in the first place. For it to become common knowledge it would have to be part of a significant percentage of interview screens across the industry. Evidently that hasn't happened, and I wonder if it ever will.
- meritt 14y ago> All the candidates came to us pre-screened by a recruiting company. Immediately end business relationships with that recruiting firm and start doing phone interviews yourself. Someone failing FizzBuzz during an in-person interview is also a red-flag on your hiring process.
- raganwald 14y agoI recall being sent to a programming interview by a recruiting company. The recruiter coached me on questions the company had asked previous applicants and then debriefed me afterwards to find out what I'd been asked. This person was definitely not acting in their client's best interests.
- codesuela 14y agoDoes someone else have a few programming tests on hand aside from FizzBuzz? Also InterviewStreet ( https://www.interviewstreet.com/ https://www.interviewstreet.com/ ) has a nice collection of problems of varying degrees of difficulty. Quite handy if you want to "prepare" for an interview.
- gacba 14y agoThat's the beauty of FizzBuzz, you don't really need other tests. It weeds out the dead wood very quickly and when you have 10 resumes to walk through in a week, that's a handy thing. Best to know this early on to avoid wasting your time and the candidate's as well.
- eli 14y agoOther examples of FizzBuzz-level tests? They aren't exactly tough to come up with. I used to ask for a function that takes a string and returns a boolean indicating whether or not it contains all uppercase letter.
- tkahnoski 14y agoPre-Screen for us is simply provide working code that 'Finds the the four highest integers in a list of integers'. We accept any language. The controversial bit, is we ask for Big O of their solution. There are a lot of candidates who didn't get the CS degree and struggle with this, surprisingly no one has ever said "I don't know Big O". Generally, working code is enough to at least get you in the door for a face-to-face. Yet this alone filters out more than 50% of the resumes.
- deleted 14y ago[deleted]
- dpritchett 14y agoFun! Here's Ruby: def top_four_ints_from(input_list) working_set = [] input_list.each do |n| working_set.push(n) working_set.sort!.shift while working_set.count > 4 end working_set end I'm pretty sure that's O(n). Constant time to insert any one value to the working set, Roughly n sorts performed but since each individual sort covers at most five elements we're still at (5 lg 5) * n -> O(n).
- yllus 14y ago80% of applicants for an internship at a company I used to work at failed FizzBuzz when I applied it to them (same deal, pencil and paper and a choice of any language they want). The worst was one perky young woman who wrote her answer in three minutes flat, handed it back and asked, "Did I get it right?" I answered, "No...." and from that point on it became the most awkward interview ever.
- Spoom 14y agoAssuming it's for a developer position, why would you continue the interview if they failed FizzBuzz?
- yllus 14y agoThe interviews were for all of 15 minutes anyways. I'm not so bent on time efficiency that I felt it necessary to save myself and the applicant twelve minutes by concluding the interview early. Also, I'm human and that's a level of cold that I didn't want to go to.
- masklinn 14y agoCould be skilled in an other field, or just an interesting conversation. If the interview's scheduled for a fixed time anyway, might as well make the best of it.
- talmand 14y agoMaybe you should administer the test towards the end of the interview after you've gotten to know the candidate a bit and allowed for time for their nervousness to wear off.
- Lambent_Cactus 14y agoIf 80% of candidates are failing, you want to ask it right at the start, to minimize the time you waste interviewing people who aren't qualified.
- 14y ago
- fusiongyro 14y agoIt's true. Of the last four or so candidates we've had, only one managed to do FB and none had heard of it. One of them, once presented with the problem, even said "Why on earth would I want to do that?" to which I replied "Because you want the job?"
- talmand 14y agoWith an answer like that I would have assumed you were a jerk. You could have easily answered the question in a positive manner that explained your need to have the candidate complete the task. "Because I said so" is often a valid answer to a child, but not to an adult. What I'm curious about is why so many seem so beholden to FizzBuzz in the first place to the point they assume everyone already knows what it is. The fact that none of your candidates had heard of FizzBuzz was to your advantage. What's the point of administering a test if everyone had already heard of it and knew the answer? So, did you hire the one candidate that completed FizzBuzz and did you hire this person because they could?
- jlgreco 14y agoI'm sure someone will drag out the extreme counter-example after I say this, but I am pretty sure nobody ever has ever advocated hiring a person simply because they can do fizz-buzz. Fizz-buzz is just one step in many of a noise filtering process.
- talmand 14y agoI'm not saying they should, I'm just curious about the outcome of this round of interviews. I've interviewed many a "web designer" that were obviously not qualified on the level they claim. Just asking how to make text flow around an image is a simple gotcha that someone who claims to hand code HTML should know. If you're just a designer then that's fine, but don't say you can hand code HTML and not know what a float is or even have creative solution that doesn't involve a float. I've met many who couldn't come up with a reasonable answer. But it's not an immediate "sorry, you should go now" moment for me when they cannot do so. I also look into how they answer and how they handle being told they were wrong. Something like FizzBuzz is a useful tool but I see too many give it too much weight without considering other variables involved in giving the test. Each interviewer has their own style but having a heavy hand on one or two aspects of the interview means you may be passing up a good hire. If I had followed the "rules" that I've seen many advocate then one of the best hires I had ever seen wouldn't have walked through the door and even then he would have been told to walk right back out. Turned out he was an excellent hire that learned quickly and was excited about his work. That young man just recently started his own development company, granted its just him for now but he's got the work and chops to support it. Makes me wonder if I were a FizzBuzz or nothing kind of interviewer how things might have been different. To be honest I have no idea if he could have coded FizzBuzz, I didn't ask. But I also understand if you are going through dozens or hundreds of resumes then you have to do something. Just don't be the "I don't hire unlucky people" guy that throws away half the resumes when starting. Too many FizzBuzz advocates get dangerously close to that kind of attitude.
- Deestan 14y ago> I can’t go fairly judge other programmers with FizzBuzz without going through the test myself. I implemented it in Ruby, my go-to language for hammering out quick solutions, and in the spirit of fairness to those I interviewed, I did it with pen and paper on the first day of the interviews (and confirmed it by entering and running it) Be careful with this kind of test evaluation: 1. The problem isn't new to you - you have already had the problem in your head for days or even years. Whether you admit it or not, you already have a good idea of how to approach the problem. 2. You are not under stress, as the candidate would be.
- sync 14y agoHis solution isn't even correct, failing his own test. if !multiple_of_3(i) && !multiple_of_5(i) output = i edit: In order to avoid overwriting output, the solution should read... if !multiple_of_3(i) && !multiple_of_5(i) output << i
- deleted 14y ago[deleted]
- raganwald 14y agoThat's probably deliberate: he says himself (and I agree with this approach) that the point is to figure out if someone knows how to program at all. Off by one errors, syntax errors, these are not all that relevant. The failures are the ones who stare at the paper blankly, or have no idea that they need a loop, or some other such hopeless approach. If you get "close enough" on paper and pencil under the pressure of an interview, that's great. You can walk through debugging it if you want to see more, but I wouldn't hold even basic logic errors against someone. I certainly admit that when coding on my own I usually get all kinds of stuff wrong that I fix as I write tests and iterate.
- lucisferre 14y agoYeah I've used FizzBuzz myself, and under interview conditions it's actually much harder to implement a correct (for edge cases, etc.) solution in a short time. I always took that into account. However I also added the twist that I wanted the candidates to also write the tests for the program in TDD style. I hoped that this would actually help, by asking the interviewee to follow a repeatable pattern of first expressing what they wanted to code to do and then implementing. We also did ping-pong pairing so I could help write a test, or do an implementation if things were going poorly, to see if that would jump start the candidates brain into the problem. The results were quite frankly a disaster, no better than what Joey found (though I didn't do enough interviews for a statistical sample). Unfortunately my limited observations have lead me to believe that too many developers (particularly in the enterprise environments) are used to working on legacy codebases that they hack and change until the bug they are fixing goes away. Many rarely implement features much, if at all, and the ones they do are heavily broken.
- MatthewPhillips 14y agoYesterday we got "OOP isn't that great", today we get FizzBuzz... must be that time of the month. We're probably due for a "idea-guys are worthless" here soon.
- lukeholder 14y agoI have a great idea then: http://www.youtube.com/watch?v=DkGMY63FF3Q http://www.youtube.com/watch?v=DkGMY63FF3Q
- goostavos 14y agoHacker News as of late has given me quite a bit of hope that I'll be able to actually get a job writing code one day (anyone need an intern? ;) ) between this FizzBuzz thing, and hearing about people who've never heard of multi-dimensional arrays, I'm feeling a little more confident..! Of the authors three ideas as to the reason for the inability of candidates to pass the test, I can perhaps understand the first two. My younger days involved copying/pasting Actionscript2 code and relying on superstition to get it working. All the while having no idea of how the fundamental constructs (like loops) even worked. What I don't understand is how someone has the confidence to apply to a job/hold down a job when their coding style is cut and paste. His final point has me scratching my head a bit. Specialist or not, aren't loops and conditional logic kind of the fundamental tools in all languages. What would the discipline be that has you coding in a specialist niche, but not using loops or conditionals?
- fusiongyro 14y agoPerhaps what you're experiencing is the Dunning-Kruger effect: that people who are unskilled frequently rank themselves as more competent than people who actually are skilled.
- goostavos 14y agoHmm.. perhaps. Still it seems a wildly bold to overestimate yourself by such a large amount. We're talking about the absolute basics here. I mean, I look at job postings and come away depressed after realizing I don't recognize half the stuff they want 5+ years experience in. So what does for-loop-not-knowing guy think we he sees the same requirements? I dunno. I just think it's strange that they even get to the interview stage.
- jccc 14y ago40% of the candidates passed the FizzBuzz test I do not object to the broad points being made here but I do object to this interpretation. It's beyond awkward for many good valuable programmers, stifling really, to do this kind of unrealistic audition programming for a live audience. You are not just under stress -- you are far, far, far outside of any demonstration of your true value to the employer. Perhaps the hiring pool really is that bad, you have a giant pile of unqualified applicants, and you really must use this kind of blunt instrument rather than taking the time to talk with candidates and their references and really get to know their work and their reputations. I've never had to do hiring and I don't envy you if you do. But I've also never in my life had to do this kind of test, and I think I'd use it as a filter myself to avoid working for someone who uses it. [EDIT: I assumed it would be clear that I'm not talking about the coding challenge of FizzBuzz. I'm talking about the experience of audition-style programming. You end up filtering on less important characteristics of applicants who might otherwise be your best candidates, but think you're filtering on FizzBuzz.]
- henrikschroder 14y agoFizzbuzz is unrealistic? Really? It's a for-loop, some conditionals, and printing. If you can't produce this in a few minutes, you can not program. The point isn't to make a perfect, working fizzbuzz in the first try, the point is to find out if your applicant can program at all in the first place. Ridiculously enough, there are people that can't program that would pass a normal interview with flying colours, but who utterly fail at fizzbuzz, which makes it a very valuable tool.
- jccc 14y agoProgramming on paper opposite an examiner with a stopwatch is indeed unrealistic. I don't disagree that FizzBuzz is crazy simple as a programming challenge.
- henrikschroder 14y agoI agree as well, which is why it's very important that you don't do that as an interviewer. The important thing is to check if the applicant can write a little bit of code from scratch, not if they can do it on time, in front of a big audience, without errors, with extra stress added on top. And it sounds like the OP did it in an ok way, and didn't scare away any great programmers, which makes his conclusion pretty valid, that 60% of his applicants simply weren't capable.
- 46Bit 14y agoAt this point, I'd think the FizzBuzz test is to get people to explain what the FizzBuzz test was. Most programmers I'd want to hire would probably have heard of at least the vague problem,
- tvjunky 14y agoHaving been on both sides the interview process and going through hundreds of candidates, I agree that a code solving problem is a valuable gauge for the technical acumen of the candidate. In fact the best experiences I have had on both sides of the table have had a well thought out coding element included. The better ones had a more real world requirement and aren't so puzzle like (yes FizzBuzz is pretty simplistic, but it’s still a puzzle). The biggest issue I see with this approach is the “On Paper” (white board applies as well) code. This is an unrealistic expectation. Unless you’re writing all your code on paper and this is a basic skill for your process, you've already added a factor that may push a normally fine developer out. If language is unimportant, then process should be as well. Let the developer solve the problem in the best way they can, even if they do ‘Google’ it. You can use the amount of ‘googleing’ as another factor to evaluate.
- dean 14y agoI agree, let them use a computer, however I would just yank out the ethernet cable. I don't want to see how well someone can Google.
- tvjunky 14y agoI see the point. Still you're not testing how the candidate works. No one knows everything about everything. We are looking for the right team member to solve business problems, full stop. Shipped code always wins over the perfect algorithm sketched on the whiteboard.
- jlgreco 14y agoThink of it more as "testing how they don't work." A computer without google ensures that, however they may work, "google it" is not their only method. I don't want to hire somebody that can only "ship" with google.
- tvjunky 14y agoI still see your point. However, how do you solve a problem if you just don't know something? To me, a big factor in this test is, did they finish and does it work? Lets say they understand that Modulo would be the way to go but they are unsure of the syntax. Where would they find the answer? Or do we say, sorry you're out...you must memorize everything?
- ashray 14y agoIs it just me or does his "sample" program look needlessly complex ? Does he really need to create all those function definitions ? I'm not super familiar with ruby but those ARE function definitions - right ? Since when is it good programming practice to have functions for every little thing ? (I'm picturing myself scrolling or jumping around in an editor to figure out what exactly the call does). This is like doing hello world with a function. Or having a function to add two numbers. Yes, sometimes it's necessary for syntactical clarity but in this case it just seems like overkill. Also why are some people on HN talking about edge cases to FizzBuzz ? There are no edge cases that I know of unless you talk about the number zero - which isn't part of the question. EDIT: Why the downvotes? I don't see why trying to discuss what's clearly a programming related problem on HN brings you downvotes ? Interesting.
- zacharydanger 14y agoYes. Who would give functions such cryptic names as "multiple_of_3" or "multiple_of_5".
- brabbins 14y agoOne of the good things about this is it's easy to change the definition of "multiple_of_3" to reflect changing requirements. For example, suppose we wanted Fizz to be printed with multiples of 7 instead. Easy! Just change: def multiple_of_3(number): number % 3 == 0 end to def multiple_of_3(number): number % 7 == 0 end Now perhaps he sees the advantage: no refactoring necessary. (* I feel I should say that I am being sarcastic. Anyone who thinks it's ok to have a function called "multiple_of_3" that checks if it is a multiple of 7 should probably be fired immediately.)
- ashray 14y agoYes, I see your point. But in this case if I wanted to change it to do it on 7, I'd have to make a change in 3 places. 1. The function definition (def multiple_of_3) 2. The function contents (number % 3 == 0) 3. The function call(s). If I didn't try to use functions on this, I'd just have to change a single line (or two at the most) in my program and get on with it. Your use case is exactly what I meant when I said that breaking such a simple problem into functions actually introduces complexity.
- rplnt 14y agoI like the problem of printing the leap years (or deciding if a year is leap). It's the same as FizzBuzz in the core (though a bit more complicated), but presents itself as something real, not like an artificial task. And as a bonus, you can see if the applicant knows the rules for inserting leap years (there are no negative points for not knowing that, only positive if you do).
- modernerd 14y agoThe trouble with more practical tests like this is that good languages are already full of practical methods. e.g. Ruby: Date.leap?(2000) # => true So you might inadvertently end up testing a candidate's knowledge of their language's standard libraries, unless you forbid them from using these. I suspect that's why more artificial tasks like FizzBuzz are still popular.
- hga 14y agoIsn't this the point where you congratulate the interviewee on the breadth of their off the top of their head Ruby knowledge ... and then ask them to do it by hand? Surely the latter won't be a surprise; if I answered like that I'd do it with a grin and a "Well, I could do it like this [write out the above], but I suspect you want something more like this [then write an implementation of the method]."
- mynameishere 14y agoI think you could save time by showing people code like this: int x=5 % 3 and asking "What is the value of x?" Because a lot of jobs are CRUD and that form of programming rarely involves the modulus operator.
- dllthomas 14y agoWell, assuming it's Haskell (given the lack of semicolon and otherwise valid Haskell syntax): x is an unused variable in the function "int" you're defining. This function returns the ratio (as a ratio, not a float) 5 / 3 for any argument, and is equivalent to "int = const (5 % 3)", which you would be more likely to see (probably inlined).
- mark-r 14y agoYou don't actually need the modulus operator, although it makes things simpler. Just use (x/3)*3==x instead.
- jpdoctor 14y ago> I was surprised to find that only one of the candidates had heard of FizzBuzz. If you were being handed a high fastball over the plate, would you let the interviewer know it was a high fastball over the plate?
- jlgreco 14y agoI do, yes. I figure doing so probably looks better than being able to answer the question (or rather, than just being able to answer the question, since you still answer it of course).
- dpritchett 14y agoOne time I got dinged for using a library to calculate standard deviation (as a part of larger solution) rather than doing the math by hand. I guess I assumed they were more interested in codecraft than in arithmetic and I was wrong.
- jlgreco 14y agoAh, that's pretty crappy. I try to avoid that sort of thing by prefacing all library calls / fancy language features with a "I'm going to just use [this thing]. If you want me to go into that, I can". Not so much ask permission as tell them. It's really a pain in the ass to have to be on guard like that though.
- bad_user 14y agoI wonder what would happen if you gave the interviewer a piece of code that's not familiar to him, e.g... val translation = List(3 -> "Fizz", 5 -> "Buzz") val numbers = { def start(from: Int): Stream[Int] = from #:: start(from+1) start(1) } val fizzbuzz = numbers.map(nr => translation.collect { case (k,value) if nr % k == 0 => value } .reduceLeftOption(_+_) .getOrElse(nr.toString)) println( fizzbuzz.take(100).mkString("\n") )
- jlgreco 14y agoIf the interviewer were good, they would play it cool and immediately ask the candidate to walk through the code out-loud and give reasons that they did what they did.
- buro9 14y agoEven with the 40% hit rate you can reduce it further by asking what could make it perform faster. "That's great for FizzBuzz to 100, but what if we went to a million? What would you do to make it perform in... I don't know, a quarter of the current execution time?" Even if they wrote a solution that avoided % or / it is always worth a few minute exploration into how one might optimise code that works today but one day is found to be slower than desired.
- buro9 14y agoIn response to an email asking for an example of a fast fizzbuzz, just avoid division. <html> <body> <script type="text/javascript"> function fastfizzbuzz() { var fizz = 1, buzz = 1, fizzbuzz = 1; for (var i = 1; i <= 100000000; i++) { if (fizzbuzz == 15) { //document.writeln('fizzbuzz<br />'); fizz = 0; buzz = 0; fizzbuzz = 0; } else if(fizz == 3) { //document.writeln('fizz<br />'); fizz = 0; } else if(buzz == 5) { //document.writeln('buzz<br />'); buzz = 0; } else { //document.writeln(i + '<br />'); } fizz++; buzz++; fizzbuzz++; } } function slowfizzbuzz() { for (var i = 1; i <= 100000000; i++) { if (i % 15 == 0) { //document.writeln('FizzBuzz<br />'); } else if (i % 3 == 0) { //document.writeln('Fizz<br />'); } else if (i % 5 == 0) { //document.writeln('Buzz<br />'); } else { //document.writeln(i + '<br />'); } } } var startTime=new Date(); fastfizzbuzz(); var endTime=new Date(); document.writeln('Fast: ' + (endTime - startTime) + 'ms<br />'); startTime=new Date(); slowfizzbuzz(); endTime=new Date(); document.writeln('Slow: ' + (endTime - startTime) + 'ms<br />'); </script> </body> </html>
- tokenadult 14y agoA thought-provoking post. I really like the specific details the author provides about the interview set-up and the results observed among candidates at his company. Now amazing as it is that there is anyone around who has not already heard of FizzBuzz as a job screen, I actually heard an even more amazing story in August 2012, which I shared here on Hacker News a month ago. http://news.ycombinator.com/item?id=4603414 http://news.ycombinator.com/item?id=4603414 The story, which no one here seemed to believe the first time I related it, but which I fear is very likely true, is that the hiring supervisor who told me this story is the lead programmer for a company that uses Web back-end programming to serve up online, adaptive lessons. He has a position open for a new programmer as the company's business grows. He has advertised in the expected places like Stack Overflow and Joel on Software. During the year 2012, the company has received many resumes. Applicants who have computer science degrees, and especially the many applicants who have master's degrees and who otherwise look all right, are invited to do a phone screen in preparation for an in-person interview. During the phone screen, the applicants log into an application that allows them to type on their own PC to write code that can be seen by the hiring supervisor. The test the hiring supervisor uses is "Write a program using a for loop to print the integers from 1 to 100." Applicants are permitted to use any language they please, and the supervisor said he would even consider correct pseudocode a successful answer. He has not yet had ANY applicant, not even one, submit a flawless working program to do that. Not one. He was eager to interview an applicant who got the test MOSTLY correct, after seeing many applicants fail to do it at all. I know the company that that hiring supervisor works for. I do not know how much its location or the fact that the software roles in that company are support roles rather than producing the company's main product may influence the desirability of the company. But somehow I think he is not lying when he says that a straightforward implementation, no tricks, of "Write a program using a for loop to print the integers from 1 to 100" is too hard for many CS graduates. That's why everyone hiring today should build a work-sample test into the hiring process. http://news.ycombinator.com/item?id=4613543 http://news.ycombinator.com/item?id=4613543 It's not clear that higher education credentials guarantee ANY minimal level of coding skill, however elementary.