Trains the technique from
LeetCode 790Domino and Tromino TilingThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
A glazier is re-leading a transom window that stands two panes tall and n panes wide, so the frame holds 2 * n panes arranged in two rows.
Two came shapes are on the bench, and the workshop has an unlimited supply of each:
Either shape may be rotated freely before it is laid down. Every pane of the frame must end up gripped by exactly one shape, and no shape may reach beyond the frame.
Count the ways to lead the whole transom. Two leadings differ when some pair of panes is gripped by one shape in the first and by two different shapes in the second. The tally climbs steeply with n, so return the remainder it leaves after division by 1000000007.
Example 1
Two leadings cover the four panes: an upright bar in each column, or a sideways bar along each row. Any elbow laid here leaves a single pane that nothing can grip.
Example 2
Eleven leadings cover the eight panes. One of them puts an upright bar in the leftmost column and a pair of locked elbows across the other columns.
Example 3
Twenty-four leadings cover the ten panes. One lays a sideways bar along each row of the two leftmost columns and locks two elbows into the rest.
Example 4
Fifty-three leadings cover the twelve panes, among them an upright bar in each of the first three columns with two locked elbows filling the rest.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def num_tilings(n: int) -> int:public int numTilings(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.