484. Count Planter Tray Layouts
Count Planter Tray Layouts

A plant nursery has a display with 2 rows and displayLength columns of square spaces. Count the different layouts that fill the display with planter trays.

Example showing valid planter tray layouts

Method Signature

int countLayouts(int displayLength)
  • displayLength: the number of columns.
  • Return the number of valid layouts modulo 1,000,000,007.

Tray Types

  • Vertical tray: covers both spaces in one column. It cannot be placed horizontally.
  • Square tray: covers all four spaces in a 2 × 2 block.
  • L-shaped tray: covers three spaces in a 2 × 2 block. Any of its four rotations may be used.

Rules

  • There is an unlimited supply of each tray type.
  • Every space must belong to exactly one tray. Trays must stay inside the display.
  • Two layouts differ if at least one space is grouped with different spaces. Swapping identical trays or changing placement order does not create a new layout.

Constraints

  • 1 ≤ displayLength ≤ 1,000,000

Examples

Example 1

countLayouts(displayLength = 5)

Output: 18

Eight layouts use only vertical and square trays. Ten layouts include L-shaped trays.

Example 2

countLayouts(displayLength = 6)

Output: 37

There are 13 layouts with no L-shaped trays, 20 with two L-shaped trays, and 4 with four L-shaped trays.



Please use Laptop/Desktop or any other large screen to add/edit code.