Domino and Tromino Tiling - Problem

You have two types of tiles:

  • A 2 × 1 domino shape
  • A tromino shape (L-shaped)

You may rotate these shapes. Given an integer n, return the number of ways to tile a 2 × n board. Since the answer may be very large, return it modulo 109 + 7.

In a tiling, every square must be covered by a tile. Two tilings are different if and only if there are two 4-directionally adjacent cells on the board such that exactly one of the tilings has both squares occupied by a tile.

Input & Output

Example 1 — Basic Case
$ Input: n = 3
Output: 5
💡 Note: There are 5 ways to tile a 2×3 board: (1) three vertical dominos, (2) one vertical + two horizontal, (3) two horizontal + one vertical, (4) two trominos, (5) different tromino arrangement
Example 2 — Minimum Case
$ Input: n = 1
Output: 1
💡 Note: Only one way to tile a 2×1 board: place one vertical domino
Example 3 — Small Even
$ Input: n = 2
Output: 2
💡 Note: Two ways to tile a 2×2 board: (1) two vertical dominos side by side, (2) two horizontal dominos stacked

Constraints

  • 1 ≤ n ≤ 1000

Visualization

Tap to expand
Domino and Tromino Tiling: 2×3 Board ExampleAvailable Tiles:VerticalDominoHorizontalDominoTromino(L-shape)2×3 Board Solutions:Way 1: Three verticalsWay 2: Mixed tilesWay 3: Horizontal + verticalWay 4&5: Tromino pairsTotal: 5 different ways to tile 2×3 board
Understanding the Visualization
1
Input
Board dimensions: 2×n where n=3
2
Tiles
Two types: domino (1×2) and tromino (L-shaped)
3
Output
Count all possible ways to tile the board
Key Takeaway
🎯 Key Insight: Use DP with three states to track board coverage patterns efficiently
Asked in
Google 15 Amazon 12 Microsoft 8
23.4K Views
Medium Frequency
~25 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen