Ctrl K

Paving a Narrow Path

Medium
A garden path is 2 cells wide and length cells long. It is paved with two kinds of tiles: a 2×1 rectangle (two cells) and an L-shaped corner tile made of three cells. Tiles can be rotated any way you like. In how many ways can the whole path be paved so that every cell is covered by exactly one tile? Two pavings are different if there are two side-adjacent cells that share a tile in one paving but belong to different tiles in the other. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
length=2 → 2

Two 2×1 tiles go either both upright or both lengthwise: 2 ways. Corner tiles cannot fill a 2×2 strip without gaps.

Example 2
length=3 → 5

Three layouts use only rectangles, and two more interlock a pair of corner tiles. 5 in total.

Example 3
length=5 → 24
Constraints
  • 1 ≤ length ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsLongest Mirror Fragment MediumAll Balanced Bracket Strings MediumFewest Jumps to the End MediumMost Profitable Streak MediumReach the Last Cell Medium
loading Python…
Input
length=2
Expected
2

Run checks the first 3 tests in your browser. Submit checks all 33 tests on the server, hidden ones included.