ProgrammingHardTCS CodeVita · Infosys HackWithInfy

What is printed?

What is printed?
from functools import lru_cache
@lru_cache(None)
def f(n):
    return n if n < 2 else f(n - 1) + f(n - 2)
print(f(90))
  1. A. 1548008755920
  2. B. 4660046610375530309
  3. C. 2880067194370816120
  4. D. 2880067194370816121

Correct answer: C. 2880067194370816120

F(90) = 2880067194370816120. lru_cache makes the calls linear, so this runs fast. The recursion depth is 90, which is well within the default limit.

More Python Programming questions

Exams that ask this topic