FastPrepDomino and Tromino Tiling
Problem · Dynamic Programming

Domino and Tromino Tiling

Learn this problem
MediumAmazon logoAmazonFULLTIMEONSITE INTERVIEW
See Amazon hiring insights

Problem statement

You have a board with 2 rows and n columns. Cover every square exactly once using any number of the following tiles:

  • A 2 x 1 domino, which may be rotated.
  • An L-shaped tromino made of three unit squares, which may be rotated.

Return the number of distinct complete tilings modulo 10^9 + 7. Two tilings are different when at least one tile covers a different set of squares.

Function

numTilings(n: int) → int

Examples

Example 1

n = 1return = 1

One vertical domino is the only complete tiling.

Example 2

n = 3return = 5

There are three domino-only tilings and two tilings that use a complementary pair of trominoes.

Example 3

n = 5return = 24

The dynamic recurrence counts 24 complete tilings.

Constraints

  • 1 <= n <= 1000.

More Amazon problems

drafts saved locally
public int numTilings(int n) {
  // write your code here
}
n1
expected1
checking account