Domanda di colloquio di Meta

Write a method to generate the Fibonacci series

Risposte di colloquio

Anonimo

16 apr 2010

void print_fib(int length) { int prev_prev = 0, prev = 1, current = 1; while (length--) { printf(" %d", prev_prev); prev_prev = prev; prev = current; current = prev_prev + prev; } printf("\n"); }

2

Anonimo

20 nov 2011

tail recursion is far from enough to make recursion fast enough, you'll need to use memoization, and even if you do that, the code will still be slower and especially much more memory consuming than the one in the post of April 15, 2010 Recursion without memoization will take exponential time.

Anonimo

14 ott 2010

The recursive Sep 24 answer is too inefficient; you can still use recursion if you want, but think of a tail recursive method...

Anonimo

3 apr 2010

Write a method to generate the Fibonacci series

Anonimo

24 set 2010

int fib(int n) { if (n < 2) return n; return fib(n - 1) + fib(n - 2); }