Pergunta de entrevista da empresa Meta

Write a method to generate the Fibonacci series

Respostas da entrevista

Sigiloso

16 de abr. de 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

Sigiloso

20 de nov. de 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.

Sigiloso

14 de out. de 2010

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

Sigiloso

3 de abr. de 2010

Write a method to generate the Fibonacci series

Sigiloso

24 de set. de 2010

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