ProgrammingHardTCS CodeVita · Infosys HackWithInfy
What is printed?
What is printed?
h = 0
for ch in 'abc':
h = (h * 31 + ord(ch)) % 1000
print(h)- A. 990
- B. 3
- C. 1000
- D. 354
Correct answer: D. 354
The rolling hash goes 97, then (97 * 31 + 98) mod 1000 = 105, then (105 * 31 + 99) mod 1000 = 354.
More Python Programming questions
- What is printed? python grid = ['a..', '.a.', '...'] cnt = sum(row.count('.') for row in grid) diag = ''.join(grid[i][i] for i in…
- What is printed? python from collections import Counter c = Counter('abracadabra') print(sum(v for v in c.values() if v % 2), len(c)…
- What is printed? python x = 0b1010 y = 0o17 z = 0xFF print(x ^ y, x | z, z >> 4, y & ~x)
- What is printed? python a = 'Python' print(a[::-1][1:4], a[-2:] + a[:2], a.upper()[::2])
- What is printed? python n = 10 6 s = 0 i = 1 while i <= n: s += n // i i = 10 print(s)
- What is printed? python def matmul(A, B, m): return [[sum(A[i][k] B[k][j] for k in range(2)) % m for j in range(2)] for i in range(2)] def…