Pergunta de entrevista da empresa Paycom

Get the n-th Fibonacci number

Respostas da entrevista

Sigiloso

21 de set. de 2020

# use Binet's formula to find nth fib number binetFib = lambda n : int(((1+sqrt(5))**n - (1-sqrt(5))**n)/(2**n*sqrt(5)))

Sigiloso

24 de mai. de 2020

def fib(n): if n==0: return 1 if n==1: return 1 return fib(n-1) + fib(n-2) RunTime =O(2^n). To improve this, one can use dynamic programming. We can use memoization. This involves using a list to reduce the number of function calls.