HARDasked at 1 company

Number of Ways to Paint N × 3 Grid

A hard-tier problem at 65% community acceptance, tagged with Dynamic Programming. Reported in interviews at Fortinet and 0 others.

Founder's read

You're looking at a hard DP problem with a 65% acceptance rate, which means most candidates who attempt it either nail the pattern or get stuck on the state representation. Fortinet has asked this. The trap is treating it as a 2D grid DP when it's really about column-by-column transitions and valid colorings. If you've only done straightforward grid problems, the constraint that adjacent cells can't share a color will catch you off guard. When this hits your live assessment and you're staring at a blank solution, StealthCoder solves it in seconds invisible to the proctor, surfacing the working transition logic before you lose time reframing.

Companies asking
1
Difficulty
HARD
Acceptance
65%

Companies that ask "Number of Ways to Paint N × 3 Grid"

If this hits your live OA

Number of Ways to Paint N × 3 Grid is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by a senior engineer who knows the OA is theater. This is the script.

Get StealthCoder
What this means

The key insight is that you don't need to track the entire grid state. Instead, process column by column and encode which color pattern the current column has. Each column is a vertical sequence of 3 cells, and you need valid colorings where no two adjacent cells (horizontally or vertically) share a color. The trick is enumerating all valid column colorings upfront, then building transitions between consecutive columns. Common misses: trying to DP on individual cells, overcomplicating the state space, or not pre-filtering invalid column patterns. Many candidates overthink adjacency constraints and burn time debugging. The real solution is small, elegant math once you see that only certain column patterns can follow others. Dynamic Programming here means summing ways to reach each valid column state based on the previous column's state.

Pattern tags

The honest play

You know the problem. Make sure you actually pass it.

Number of Ways to Paint N × 3 Grid recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by a senior engineer who knows the OA is theater. This is the script. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Number of Ways to Paint N × 3 Grid interview FAQ

Why is this a hard problem when the grid is only 3 wide?+

The width is fixed at 3, but the depth is N, and you need to count all valid N-length colorings. The hard rating comes from the pattern recognition required: realizing columns are independent state units and enumerating valid transitions is non-obvious. Once you see it, the DP is straightforward.

Do I need to track the entire grid or can I use column-by-column DP?+

Column-by-column is the intended approach. Each column's coloring constrains only the next column's options. Store the count of ways to reach each valid column state, transition based on valid adjacency, and sum at the end. This keeps space and time polynomial.

How many valid colorings does a single column have?+

With 3 cells and k colors where no two adjacent cells match, there are 6k(k-1)^2 valid patterns per column if you pre-compute them. The exact count depends on the input, but enumerate them first and build transitions between valid pairs, not from scratch each iteration.

What's the most common mistake candidates make here?+

Trying to brute-force all 3^N colorings or using a state space that tracks too much detail. The breakthrough is recognizing that the previous column's coloring is the only state that matters for validating the next column. Candidates who skip enumeration and try to compute validity on the fly usually timeout.

Is this problem still asked at FAANG or just Fortinet?+

The input shows only Fortinet has reported this problem. Lower frequency in public reports doesn't mean it won't appear; it means fewer candidates have shared it. Hard DP grid problems are always fair game at any company with strong algo expectations.

Want the actual problem statement? View "Number of Ways to Paint N × 3 Grid" on LeetCode →

Frequency and company-tag data sourced from public community-maintained interview-report repos. Problem, description, and trademark © LeetCode. StealthCoder is not affiliated with LeetCode.