ProgrammingVery hardCodeforces-style · placement coding round
What is printed?
What is printed?
from functools import lru_cache
@lru_cache(maxsize=None)
def grid(r, c):
if r == 0 or c == 0:
return 1
return grid(r - 1, c) + grid(r, c - 1)
print(grid(3, 3), grid.cache_info().currsize)- A. 19 16
- B. 20 16
- C. 20 15
- D. 20 12
Correct answer: C. 20 15
C(6,3) = 20 is the number of monotone lattice paths. The cache holds one entry for each reached (r, c) pair except (0, 0), which is never called, so there are 15 entries.
More Python Programming questions
- What is printed? python def cancomplete(gas, cost): total = tank = start = 0 for i in range(len(gas)): d = gas[i] - cost[i] total += d…
- What is printed? python x = 0b101100 print(x & (x - 1), x & -x, bin(x).count('1'))
- What is printed? python M = 1000000007 print(pow(2, -1, 7), pow(3, 4, 5), (pow(10, 9, M) 2) % M)
- What is printed? python import math print(math.comb(10, 3), math.gcd(12, 18, 24), math.lcm(4, 6, 10))
- What is printed? python import itertools print(sum(b - a for a, b in itertools.pairwise([1, 4, 2, 8])))
- What is printed? python g = [[0] 3] 2 g[0][1] = 5 h = [[0] 3 for in range(2)] h[0][1] = 5 print(g, h)