Skip to content

Practice Number of Ways to Paint N × 3 Grid

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#1411
LeetCode Problem

Number of Ways to Paint N × 3 Grid

Problem Statement

You have a grid of size n x 3 and you want to paint each cell of the grid with exactly one of the three colors: Red, Yellow, or Green while making sure that no two adjacent cells have the same color (i.e., no two cells that share vertical or horizontal sides have the same color). Given n the number of rows of the grid, return the number of ways you can paint this grid. As the answer may grow large, the answer must be computed modulo 10^9 + 7.

Source: Number of Ways to Paint N × 3 Grid on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
n = 1
Output
12

# Example 2

Input
n = 5000
Output
30228214

Constraints

n == grid.length
1 <= n <= 5000

Related LeetCode Problems

Practice more problems similar to Number of Ways to Paint N × 3 Grid.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.