ProgrammingVery hardTCS NQT · Wipro pattern
What is printed?
What is printed?
from functools import lru_cache
@lru_cache(maxsize=2)
def sq(x):
return x * x
for v in [1, 2, 1, 3, 1]:
sq(v)
print(sq.cache_info().hits, sq.cache_info().misses)- A. 1 4
- B. 2 3
- C. 2 4
- D. 3 2
Correct answer: B. 2 3
Calls 1 and 2 miss, the second 1 hits, and 3 misses and evicts the least recently used key 2. The final 1 hits, giving 2 hits and 3 misses.
More Python Programming questions
- What is printed? python def nge(a): res = [-1] len(a) st = [] for i, x in enumerate(a): while st and a[st[-1]] < x: res[st.pop()] = x…
- What is printed? python def pickbystart(iv): iv = sorted(iv) cnt, end = 0, -109 for s, e in iv: if s >= end: cnt += 1 end = e return cnt…
- In CPython, which operation on a collections.deque is O(n) in the worst case?
- What is printed? python def primes(n): s = [True] (n + 1) s[0:2] = [False, False] for i in range(2, int(n 0.5) + 1): if s[i]: s[i i::i] =…
- What is printed? python def merge(a, b): i = j = 0 out = [] while i < len(a) and j < len(b): if a[i] <= b[j]: out.append(a[i]) i += 1…
- What is printed? python from collections import deque def maxdist(g): R, C = len(g), len(g[0]) d = [[-1] C for in range(R)] q = deque()…