Microsoft Interview Question

write a function to find the n-th fibonacci number

Interview Answers

Anonymous

Mar 9, 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.

Anonymous

May 19, 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); }