Count Tilings with Dominoes and L-Shaped Trominoes

Quick Overview

Count Tilings with Dominoes and L-Shaped Trominoes. Tile a 2-by-n board completely using 2-by-1 dominoes and L-shaped three-cell trominoes, allowing rotations.

Count Tilings with Dominoes and L-Shaped Trominoes

Company: Goldman Sachs

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Other

### Problem Tile a 2-by-n board completely using 2-by-1 dominoes and L-shaped three-cell trominoes, allowing rotations. Tiles may not overlap or extend outside the board. Count distinct tile placements modulo 1000000007; placements differ when some adjacent cell pair belongs to one tile in exactly one placement. ```cpp class Solution { public: int numTilings(int n); }; ``` ### Examples **Example 1:** ```text n = 2 Output: 2 Explanation: Use two vertical dominoes or two horizontal dominoes. ``` **Example 2:** ```text n = 4 Output: 11 Explanation: With full-board counts F1=1,F2=2,F3=5 and one-corner-missing count G3=2, F4=F3+F2+2*G3=11. ``` ### Constraints - Board length n lies in [1,1000]. - Return the count modulo 1000000007. ### Contract considerations Preserve rotation and the original notion of distinct tile placements. ```hint Read the boundary condition Which incomplete boundary shape is needed beside a full-board DP state? ``` ### Boundary reminders Preserve rotation and the original notion of distinct tile placements.

Overview: Count Tilings with Dominoes and L-Shaped Trominoes. Tile a 2-by-n board completely using 2-by-1 dominoes and L-shaped three-cell trominoes, allowing rotations.

Goldman Sachs logo
Goldman Sachs
Source window: 0–3 months · as of Oct 21, 2026
mediumSoftware EngineerOtherCoding & Algorithms
1
0

Problem

Tile a 2-by-n board completely using 2-by-1 dominoes and L-shaped three-cell trominoes, allowing rotations. Tiles may not overlap or extend outside the board. Count distinct tile placements modulo 1000000007; placements differ when some adjacent cell pair belongs to one tile in exactly one placement.

class Solution {
public:
    int numTilings(int n);
};

Examples

Example 1:

n = 2
Output: 2
Explanation: Use two vertical dominoes or two horizontal dominoes.

Example 2:

n = 4
Output: 11
Explanation: With full-board counts F1=1,F2=2,F3=5 and one-corner-missing count G3=2, F4=F3+F2+2*G3=11.

Constraints

  • Board length n lies in [1,1000].
  • Return the count modulo 1000000007.

Contract considerations

Preserve rotation and the original notion of distinct tile placements.

Boundary reminders

Preserve rotation and the original notion of distinct tile placements.