4 ms·
Lol, I've been doing this for 11 years and doing Fibonacci off the top of my head would make me sweat. To me it seems a fairly unimportant exercise that proves
by donatj 9y ago
Lol, I've been doing this for 11 years and doing Fibonacci off the top of my head would make me sweat.
To me it seems a fairly unimportant exercise that proves little other than that you know the formula for the Fibonacci sequence of the top of your head under duress.
- fancyPantsZero 9y agoI'd assume that the interviewer would describe the formula for Fibonacci if asked. This type of question is more of a Fizzbuzz (i.e. testing for very basic programming ability) than a formula quiz.
- bcherny 9y agoIn an interview setting, I'm sure you could hack something together and then improve it! Eg. an iterative Fibonacci is easy to reason about if you're not used to recursion. It's a good question for junior people because there's so many ways to write it: iterative, recursive, recursive + memoized, eagerly streamed, lazily streamed. That said, it is not a problem you'll have in the real world, so at best it's good to get a feel for how a candidate thinks through problems, how easily they can reframe an algorithm in different ways, and how they can reason about tradeoffs of different approaches.
- anyfoo 9y agoThe Fibonacci sequence is not much of a "formula", it's simply adding the previous two values in the sequence together. If you don't know that, the interviewer would probably happily tell you what it is, because the question probably aims at how you would actually implement it. Though not knowing what Fibonacci is might still be a little bit suspect, given how often it is used in examples and literature in general as a "very simple" recursive function. One might think that the candidate hasn't explored their field very much.
- tyingq 9y agoAre there bonus points for doing it in a way that doesn't hang the browser?
- lj3 9y ago16 years here and I failed a fibo question a few years ago. I don't do live coding well and it's rare to do that kind of "classic" recursion in a JS app. I've since added it to a list of practice questions I go over before I start interviewing, just in case somebody asks it.
- keithnz 9y agowhat I missed was that these are supposed to be practice questions, so while they are sucky questions, they are question worth practice as opposed to good questions to ask
- zumu 9y agoI hate fib as an interview question as well, but for the record the non-recursive while loop implementation is preferable till tail call recursion lands in major browsers.