Pergunta de entrevista da empresa Microsoft

write a function to find the n-th fibonacci number

Respostas da entrevista

Sigiloso

9 de mar. de 2016

Solved using a (overcomplicated) "dynamic programming" recursive method, runtime optimization was in the form of storing partial solutions. Accidentally stated the runtime to be O(n^2) instead of O(2^n), which I assume is where it went wrong. Could also have solved it using a simple for-loop.

Sigiloso

19 de mai. de 2016

public int FibonacciNumber(int n) { if (n == 1) return 1; else if (n == 0) return 0; else if (n < 1) return 0; else return FibonacciNumber(n - 1) + FibonacciNumber(n - 2); }