Morgan Stanley interview question

How would you code a non-recursive Fibonacci?

Interview Answer

Anonymous

Mar 1, 2024

They made me type it: public int f(int n) { int tmp; int a = 3; int b = 1; for (int i = 0; i < n; i++) { tmp = a; a = 3 * a - b; b = tmp; } return b; }