Ctrl K

Colouring a Three-Column Strip

Hard
A strip of rows rows and 3 columns is painted with three colours: each cell gets exactly one colour, and no two cells sharing a side (horizontally or vertically) may have the same colour. Count such colourings. The answer can be large, so return it modulo 10⁹ + 7.
Example 1
rows=1 → 12

Three cells in a row: the first takes any of 3 colours, each next one any of the other 2: 3 · 2 · 2 = 12.

Example 2
rows=2 → 54
Example 3
rows=3 → 246
Constraints
  • 1 ≤ rows ≤ 5000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsPattern With Dot and Star HardLongest Balanced Bracket Stretch HardWater Between Walls HardDoes the Text Fit the Pattern HardBiggest Solid Panel Block Hard
loading Python…
Input
rows=1
Expected
12

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