Skip to content
Decoder

Domino and Tromino Tiling

Medium

Problem

You want to cover a board that is 2 rows tall and `n` columns wide. You have unlimited 2 × 1 dominoes and L-shaped trominoes (three squares in an L), and you may rotate either piece. Return the number of ways to tile the whole board with no gaps or overlaps. Two tilings differ if some square is covered by a different piece. The count can be huge, so return it modulo `10^9 + 7`.

Example 1

Input
n = 1
Output
1

Example 2

Input
n = 2
Output
2
Why
two vertical dominoes, or two horizontal ones

Example 3

Input
n = 3
Output
5

Example 4

Input
n = 4
Output
11

Constraints

  • 1 <= n <= 1000

Read it once before you touch anything

Want some pressure? Start the timer. In an interview you get about two minutes to understand the problem.

  1. 1Read the goalWhat goes in, what comes out
  2. 2Scan the examplesCheck one by hand
  3. 3Note the constraintsThey set your Big O
Say what it asks in one sentence
Say it out loud first, then compare with ours.