Domino and Tromino Tiling

You have two kinds of tiles: a 2 x 1 domino and an L-shaped tromino, and both may be rotated. Given n, return the number of ways to tile a 2 x n board, modulo 10^9 + 7. Two tilings differ if some pair of 4-directionally adjacent cells is covered by one tile in one tiling and not in the other.

30:00

Domino and Tromino Tiling
medium
Free written solution
Topics
Companies

You have two kinds of tiles: a 2 x 1 domino and an L-shaped tromino, and both may be rotated. Given n, return the number of ways to tile a 2 x n board, modulo 10^9 + 7. Two tilings differ if some pair of 4-directionally adjacent cells is covered by one tile in one tiling and not in the other.

Example 1:
Input: {"n":3}
Output: 5
Constraints:
  • 1≤n≤10001 \leq n \leq 1000

Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result

Run code to see results.

Input
arr ={"n":3}

Count the ways to tile a 2 x 3 board with dominoes and L-trominoes. Counts grow fast, so everything is taken mod 1e9+7.

2 x 3 board: nothing counted yet

Variables
VariableValue
n3
DepthFunction Call
Stack empty
0/7