Millennium interview question

fibonacci and write the recursive function

Interview Answers

Anonymous

Feb 6, 2020

Your solution is incorrect, if your value of n is too high (lets say greater than 10,000) it could cause a stack overflow due to the replicated stack frames. What you want to do is provide an iterative rather than recursive solution. For example: def fibonacci(n): x = 0 ,1 for i in range(n): a,b = b,a+b return a

9

Anonymous

Feb 6, 2020

Sorry, it should be def fibonacci(n): a,b = 0,1 for i in range(n): a,b = b,a+b return a

2