Data Structures & AlgorithmsVery hardProduct Company SDE · CP practice

Problem: How many domino tilings does a 3 x 8 board have? Run the recurrence f(n) = 4 f(n-1) - f(n-2) with f(0) = 1, f(1) = 3.

Problem: How many domino tilings does a 3 x 8 board have? Run the recurrence f(n) = 4 f(n-1) - f(n-2) with f(0) = 1, f(1) = 3.
f = [1, 3]
for n in range(2, 5):
    f.append(4 * f[-1] - f[-2])
print(f[4])
What is printed?
  1. A. 41
  2. B. 571
  3. C. 153
  4. D. 34

Correct answer: C. 153

f = 1, 3, 11, 41, 153, so the 3 × 8 board (n = 4) has 153 tilings. Stopping one step early gives 41, going one step too far gives 571, and 34 counts the 2 × 8 board (Fibonacci).

More Coding Interview Problems questions

Exams that ask this topic