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)
  1. A. 19 16
  2. B. 20 16
  3. C. 20 15
  4. 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

Exams that ask this topic