HARDasked at 1 company

Painting a Grid With Three Different Colors

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

Founder's read

Google asks this problem, and candidates blank on it. You've got a grid, three colors, constraints on adjacency or color count, and the brute force explosions into 3^(n*m) possibilities. The acceptance rate sits at 78.5%, which sounds high until you realize most solves come from people who've seen the pattern before. The trick isn't the colors themselves, it's recognizing that dynamic programming can compress the state space by tracking valid color assignments per row or cell. If you hit this live and the greedy approach fails, you need to pivot fast. StealthCoder runs invisibly during your OA and surfaces the DP formulation in seconds, letting you code while the proctor sees nothing.

Companies asking
1
Difficulty
HARD
Acceptance
79%

Companies that ask "Painting a Grid With Three Different Colors"

If this hits your live OA

Painting a Grid With Three Different Colors 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE.

Get StealthCoder
What this means

The problem forces you into dynamic programming territory because the naive 3^(n*m) brute force won't run. The actual trick is state representation: instead of tracking every cell independently, you compress the state by defining valid configurations for each row (or layer) and count transitions between compatible states. Most candidates try color-by-color assignment and hit time limits immediately. The DP recurrence then becomes manageable, multiplying counts of valid previous states by valid next states. The hard part isn't the idea, it's encoding which color pairs are legal given the constraints, and ensuring your transitions don't double-count or miss valid paths. Common pitfall: forgetting to initialize base cases correctly or misunderstanding the adjacency rules. When you're stuck on encoding, StealthCoder gives you the working state-transition table instantly, so you can focus on implementation, not the conceptual wall.

Pattern tags

The honest play

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

Painting a Grid With Three Different Colors 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. Made by a working Amazon engineer who got tired of watching qualified friends bomb OAs they'd solve cold in an IDE. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Painting a Grid With Three Different Colors interview FAQ

Is this really asked at Google?+

Yes, confirmed in the data. Google has asked this problem, and it lands on live assessments, not just phone screens. The 78.5% acceptance rate suggests it's not a rare edge case either, so it belongs in your interview prep if you're targeting Google.

What's the trick that makes it hard?+

Brute force is impossibly slow. The trick is recognizing that dynamic programming with state compression works: instead of enumerating all color assignments, you track valid configurations per row and count transitions. Most candidates waste time on greedy or try to optimize the wrong layer.

How does this relate to Dynamic Programming as a topic?+

This is a classic DP problem because the answer depends on previous decisions (previous row colors), and you can't know the optimal future without exploring valid states. DP lets you avoid recomputation by memoizing valid configurations and their transition counts.

What happens if I can't solve it during the real OA?+

This is exactly where StealthCoder exists. If the pattern doesn't click during your timed assessment, the overlay reads the problem and shows you the DP formulation and state encoding, so you can code a working solution instead of spinning on the idea.

Should I memorize the solution before the OA?+

Better to understand the DP state transition concept, but honestly, grid-coloring DP problems vary enough that full memorization is fragile. Build intuition on similar problems and trust that StealthCoder covers gaps if the variant throws you.

Want the actual problem statement? View "Painting a Grid With Three Different Colors" 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.