Trains the technique from
LeetCode 1411Number of Ways to Paint N × 3 GridThis 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 panel is n rows tall and three cells wide. Each cell is to be painted red, yellow or green so that no two cells sharing an edge carry the same colour.
Return how many paintings there are, given as the remainder after dividing by 1000000007.
Example 1
Twelve rows are legal on their own. Each of the six whose ends match allows five rows below it and each of the six with three different colours allows four, which comes to fifty-four two-row panels.
Example 2
Six rows deep, the two running tallies have been stepped down five times and add to twenty-three thousand three hundred and forty-six.
Example 3
Three rows deep the count is two hundred and forty-six, small enough that the remainder never bites.
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_of_ways(n: int) -> int:public int numOfWays(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.