Participate in Codex, Test Your Skills & Win BIG

Ways to color a 3xN Board

Problem Setter: raghav_aggiwal Problem Tester: glowing_glare

Given a 3 x A board, find the number of ways to color it using at most 4 colors such that no 2 adjacent boxes have same color.

Diagonal neighbors are not treated as adjacent boxes.

Return the ways modulo 109 + 7 as the answer grows quickly.

Input Format:

The first and the only argument contains an integer, A.

Output Format:

Return an integer representing the number of ways to color the board.


1 <= A < 100000


Input 1:
    A = 1

Output 1:

Input 2:
    A = 2

Output 2:
NOTE: You only need to implement the given function. Do not read input, instead use the arguments to the function. Do not print the output, instead return values as specified. Still have a doubt? Checkout Sample Codes for more details.
Start solving Ways to color a 3xN Board on Interview Code Editor
  • Hint 1
  • Solution Approach
  • Complete Solution
Asked In:


Click here to start solving coding interview questions