Data Structures & AlgorithmsModerateProduct company OA · Amazon/Microsoft-style OA

A 2 x 7 board is to be covered by 1 x 2 dominoes (each may be placed horizontally or vertically). How many tilings are there? Use the classic 2 x n domino recurrence.

  1. A. 29
  2. B. 17
  3. C. 21
  4. D. 128

Correct answer: C. 21

For a 2 x n board, the number of domino tilings satisfies f(n) = f(n-1) + f(n-2) with f(0) = 1 and f(1) = 1, giving Fibonacci numbers. The sequence grows by one step each column, and a 2 x 7 board corresponds to the 8th Fibonacci number.

More Coding Interview Problems questions

Exams that ask this topic