Data Structures & AlgorithmsModerateProduct Company SDE · simulation round
Problem: A row of 5 cells starts as [0, 0, 1, 0, 0]. Each step, every cell becomes the XOR of its two neighbours (cells outside the row count as 0). After 2 steps, what is the sum of the cells? Run the simulation.
Problem: A row of 5 cells starts as [0, 0, 1, 0, 0]. Each step, every cell becomes the XOR of its two neighbours (cells outside the row count as 0). After 2 steps, what is the sum of the cells? Run the simulation.
s = [0, 0, 1, 0, 0]
for _ in range(2):
s = [(s[i - 1] if i > 0 else 0) ^ (s[i + 1] if i + 1 < len(s) else 0) for i in range(len(s))]
print(sum(s))What is printed?- A. 1
- B. 3
- C. 2
- D. 0
Correct answer: C. 2
After step 1 the row is [0,1,0,1,0] and after step 2 it is [1,0,0,0,1], which sums to 2. Forgetting the boundary zeros changes the result.
More Coding Interview Problems questions
- Problem: What is the exponent of the prime 3 in 100!? Use Legendre's formula, summing 100 // 3^k. Run the code. python print(sum(100 // 3…
- Problem: How many collinear triples of points does the 3 x 3 grid {0,1,2}^2 contain? Use the cross-product test below. python from…
- Problem: How many integers x in [1, 60] satisfy x ≡ 2 (mod 3) and x ≡ 3 (mod 4)? Run the code. python print(sum(1 for x in range(1, 61) if…
- Problem: How many unordered pairs from {1, 2, 3, 4, 5, 6} have XOR equal to 7? Run the code. python from itertools import combinations…
- Problem: How many palindromic substrings of length at least 1 does 'abcba' contain? Run the code. python s = 'abcba' print(sum(1 for i in…
- Problem: What is the smallest positive integer whose decimal digits multiply to 36? Run the search code. python x = 1 while True: p = 1…