Domino and Tromino Tiling

MediumDynamic Programming1d dp

Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.

Practice this as a mock interviewFree to start, no account needed

Problem

You have unlimited 1 x 2 dominoes and L-shaped trominoes (three cells forming an L inside a 2 x 2 square). Both shapes may be rotated. Return the number of ways to completely cover a 2 x n board with these tiles, without overlaps and without anything hanging off the board. Two tilings are different if some pair of edge-adjacent cells is covered by the same tile in one tiling and by different tiles in the other. Return the count modulo 10^9 + 7.

Examples

Input: n = 3
Output: 5
Three vertical dominoes, a vertical domino plus two horizontal ones (2 placements), and two L-tromino pairings.
Input: n = 1
Output: 1
A single vertical domino.

Constraints

  • 1 <= n <= 1000

What the interviewer grades

A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.

More 1d dp problems