#1411

Number of Ways to Paint N × 3 Grid

specialist · 870 · lc hard +31 · verified · 80.5% accepted · 1,654 likes · top 92%

play →

Description

You have an n x 3 grid to color with three colors (Red, Yellow, Green) so that no two horizontally or vertically adjacent cells share a color. Given n, return the number of valid colorings modulo 109 + 7.

Example 1:

Input: n = 1
Output: 12
Explanation: There are 12 possible way to paint the grid as shown.

Example 2:

Input: n = 5000
Output: 30228214

Code

1
2
3