ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
from functools import cache
@cache
def paths(r, c):
return 1 if r == 0 or c == 0 else paths(r - 1, c) + paths(r, c - 1)
print(paths(16, 16))- A. 601080390
- B. 300540195
- C. 155117520
- D. 1073741824
Correct answer: A. 601080390
The number of lattice paths to a 16 by 16 grid is C(32, 16) = 601080390. The cache turns the exponential recursion into a 17 by 17 table of calls, and the depth stays about 32.
More Python Programming questions
- What is printed? python print(sum(map(int, str(2 100))))
- What is printed? python print(bin(12345).count('1'), len(bin(12345)) - 2)
- What is printed? python print(int(float('1e3')), int('12'))
- What is printed? python print('%5.2f|%-4d|%04x' % (3.14159, 7, 255))
- What is printed? python a = {1, 2, 3, 4} b = {3, 4, 5} print(a ^ b, a - b, b <= a, a | b == {1, 2, 3, 4, 5})
- What is printed? python print(int(2.675 100), round(2.675, 2))