Alternate FizzBuzz Questions [closed]

∥☆過路亽.° 提交于 2019-11-30 10:04:32

问题


Anybody have any good FizzBuzz type questions that are not the FizzBuzz problem?

I am interviewing someone and FB is relatively well known and not that hard to memorize, so my first stop in a search for ideas is my new addiction SO.


回答1:


I've seen a small list of relatively simple programming problems used to weed out candidates, just like FizzBuzz. Here are some of the problems I've seen, in order of increasing difficulty:

  1. Reverse a string
  2. Reverse a sentence ("bob likes dogs" -> "dogs likes bob")
  3. Find the minimum value in a list
  4. Find the maximum value in a list
  5. Calculate a remainder (given a numerator and denominator)
  6. Return distinct values from a list including duplicates (i.e. "1 3 5 3 7 3 1 1 5" -> "1 3 5 7")
  7. Return distinct values and their counts (i.e. the list above becomes "1(3) 3(3) 5(2) 7(1)")
  8. Given a string of expressions (only variables, +, and -) and a set of variable/value pairs (i.e. a=1, b=7, c=3, d=14) return the result of the expression ("a + b+c -d" would be -3).

These were for Java, and you could use the standard libraries so some of them can be extremely easy (like 6). But they work like FizzBuzz. If you have a clue about programming you should be able to do most pretty quickly. Even if you don't know the language well you should at least be able to give the idea behind how to do something.

Using this test one of my previous bosses saw everything from people who aced it all pretty quick, to people who could do most pretty quick, to one guy who couldn't answer a single one after a half hour.

I should also note: he let people use his computer while they were given these tasks. They were specifically instructed that they could use Google and the like.




回答2:


Perhaps this does not answer your question directly, but I am not certain you need to come up with another problem. Besides being "easy to memorize", the FizzBuzz question is just plain "easy", and that is the point. If the person you are interviewing is in the class of people to which FizzBuzz is "well-known", then they are in the class of people that a FizzBuzz-type question would not filter out. That does not mean that you hire them on the spot, but it does mean that they should be able to breeze through it and get on to the meat of the interview.

To put it another way, anybody who takes the time to read Coding Horror is worth interviewing further. Just have them write out the solution really quickly, discuss it briefly (e.g., How do you test this?), and then move on to the next question. And as the article says, "it is genuinely astonishing how many candidates are incapable of the simplest programming tasks."




回答3:


Any of the early ones from Project Euler would probably be good.

For example:

Problem 25

The Fibonacci sequence is defined by the recurrence relation:

Fn = Fn−1 + Fn−2, where F1 = 1 and F2 = 1.

Hence the first 12 terms will be:

F1 = 1
F2 = 1
F3 = 2
F4 = 3
F5 = 5
F6 = 8
F7 = 13
F8 = 21
F9 = 34
F10 = 55
F11 = 89
F12 = 144

The 12th term, F12, is the first term to contain three digits.

What is the index of the first term in the Fibonacci sequence to contain 1000 digits?




回答4:


I've found checking a string if it is a palindrome is a pretty simple one that can be a decent weeder.




回答5:


I wanted a FizzBuzz question that doesn't involve the modulo operator. Especially since I'm typically interviewing web developers for whom the modulo operator just doesn't come up that often. And if it's not something you run into regularly, it's one of those things you look up the few times you need it.

(Granted, it's a concept that, ideally, you should have encountered in a math course somewhere along the way, but that's a different topic.)

So, what I came up with is what I call, unimaginatively, Threes in Reverse. The instruction is:

Write a program that prints out, in reverse order, every multiple of 3 between 1 and 200.

Doing it in normal order it easy: multiply the loop index by 3 until you reach a number that exceeds 200, then quit. You don't have to worry about how many iterations to terminate after, you just keep going until you reach the first value that's too high.

But going backwards, you have to know where to start. Some might realize intuitively that 198 (3 * 66) is the highest multiple of 3, and as such, hard-code 66 into the loop. Others might use a mathematical operation (integer division or a floor() on a floating point division of 200 and 3) to figure out that number, and in doing so, provide something more generically applicable.

Essentially, it's the same sort of problem as FizzBuzz (looping through values and printing them out, with a twist). This one is a problem to solve that doesn't use anything quite as (relatively) esoteric as the modulo operation.




回答6:


For something really super-simple that can be done in 10 seconds, but would remove those people who literally can't program anything, try this one:

Ask: show me (on paper, but better on a whiteboard) how you would swap the values of two variables.

This wasn't my idea, but was posted in a comment by someone named Jacob on a blog post all about the original FizzBuzz question.

Jacob goes on to say:

If they don’t start with creating a third variable, you can pretty much write that person off. I’ve found that I can cut a third to half my (admittedly at that point unscreened) applicants with that question alone.

There is a further interesting discussion after that comment on the original blog post about ways to perform this variable swapping without requiring a third variable (adding/subtracting, xor etc.), and of course, if you're using a language that supports this in a single statement/operation, it may not be such a good test.

Although not my idea, I wanted to post this here as it's such an elegantly simple, easy question that can (and should) be answered within about 10 seconds by someone who has written even the simplest of programs. It also does not require the use of somewhat apparently obscure operators like the modulo operator, which lots of people, who are otherwise fairly decent programmers, are simply not familiar with (which I know from my own experience).




回答7:


Fibonacci, reverse a string, count number of bits set in a byte are other common ones. Project Euler also has a large collection of increasing difficulty.




回答8:


Ask them to write an app to return the factors of a given number. It's easy to do and hard to do well in a short period of time. You can see their style and the way they think through problems in a small amount of time.




回答9:


Return the index of the first occurrence of string X within string Y

Implementing strstr() requires a basic understanding of the language while providing the opportunity for clever optimization.




回答10:


If it is a C/C++ interview make sure the person knows about pointers.

General - simple algorithm ([single/double]linked list). Ask about complexity of adding in each case (at the begining, at the end, optimizations ...) ?

(General) How do you find min and max from an array (N size) with just 3*N/2 comparisons?

C/C++: How would you optimize multiple "strcat"s to a buffer ?




回答11:


Check out 6.14 from the C++ FAQ Lite:

http://www.parashift.com/c++-faq-lite/big-picture.html




回答12:


How about: I want to use a single integer to store multiple values. Describe how that would work.

If they don't have a clue about bit masks and operations, they probably can't solve other problems.




回答13:


Find a list of primes is a fairly common question but it still requires some thought and there are varying degrees of answers people might give.

You would also be surprised how many people struggle to implement a Map/Dictionary type data-structure.




回答14:


I have asked my candidates to create a program to calculate factorial of a given number in any pseudo language of their choice. It is a fairly easy problem to solve and it lends itself well to the natural followup quistions (that could often be asked) about recursion.



来源:https://stackoverflow.com/questions/117812/alternate-fizzbuzz-questions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!