Data Structures & AlgorithmsModerateProduct Company SDE · CP practice

Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP.

Problem: How many ways are there to tile a 2 x 6 board with 2 x 1 dominoes? Run the DP.
f = [1, 1]
for n in range(2, 7):
    f.append(f[-1] + f[-2])
print(f[6])
What is printed?
  1. A. 8
  2. B. 21
  3. C. 64
  4. D. 13

Correct answer: D. 13

f(n) = f(n−1) + f(n−2) with f(0) = f(1) = 1 gives 1, 1, 2, 3, 5, 8, 13, so 2 × 6 has 13 tilings. One step short gives 8, one too far gives 21, and 2⁶ = 64 treats each column independently.

More Coding Interview Problems questions

Exams that ask this topic