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))- A. 1548008755920
- B. 4660046610375530309
- C. 2880067194370816120
- 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
- What is printed? python from functools import lrucache import sys sys.setrecursionlimit(1000) @lrucache(None) def f(n): return 0 if n == 0…
- What is printed? python g = {1: [2, 3], 2: [4], 3: [], 4: []} stack = [1] out = [] while stack: u = stack.pop() out.append(u)…
- What is printed? python s = list(range(10)) print(s[8:2:-3], s[::-4], s[-3:])
- What is printed? python a = [1, 2, 3, 4, 5] a[1:3] = [9] 4 print(a)
- What is printed? python print(repr('abc'[5:]), repr('abc'[-10:2]), [1, 2][3:0:-1])
- What is printed? python s = 'banana' print(s.find('an', 2), s.rfind('an'), s.find('x'), s.index('na', 3))