HARDasked at 1 company

Paint House II

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

Founder's read

Paint House II is the harder sibling of the classic paint problem, and it hits different when the number of colors is unbounded. You've got n houses and k colors. Each house-color combo has a cost. Constraint: no two adjacent houses can share a color. LinkedIn asks this regularly, and candidates who haven't drilled it get stuck on the naive O(n*k^2) DP that times out. The trick is realizing you can compute the minimum in O(n*k) by tracking the two smallest previous costs, not recalculating the min for every state. If you blank on this live, StealthCoder surfaces the optimized recurrence in seconds, invisible to the proctor.

Companies asking
1
Difficulty
HARD
Acceptance
56%

Companies that ask "Paint House II"

If this hits your live OA

Paint House II 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround.

Get StealthCoder
What this means

The trap is building a straightforward DP where dp[i][j] = min cost to paint house i with color j, then computing dp[i][j] = cost[i][j] + min(dp[i-1][c] for all c != j). That's correct but slow. Most candidates code it, hit the time limit, and panic. The fix: precompute the global min and second-min of the previous row. If the min came from a different color, use it. If not, use the second-min. This drops complexity to O(n*k) and passes comfortably. Array and Dynamic Programming both matter here, but the optimization is what separates acceptance from TLE. When you're live and the brute force DP compiles but fails cases, that's when StealthCoder's solution appears.

Pattern tags

The honest play

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

Paint House II 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 because the OA filter rejects engineers who'd pass the on-site. That's a broken filter. This is the workaround. Works on HackerRank, CodeSignal, CoderPad, and Karat.

Paint House II interview FAQ

Is Paint House II actually asked at LinkedIn and other companies?+

LinkedIn has explicitly reported asking it. Acceptance sits at 56%, meaning it's asked often enough and hard enough that most candidates don't solve it cleanly on first attempt. It's the kind of problem that sticks in hiring loops because it filters for optimization thinking.

How does this differ from the easier Paint House problem?+

Paint House (3 colors, fixed) can brute-force with O(3*n) or O(1) space tricks. Paint House II has k colors, unbounded. The naive DP is O(n*k^2), which fails at scale. You need the min/second-min insight. Different problem class entirely.

What's the main trick to avoid timeout?+

Track the minimum and second-minimum costs from the previous house across all colors. When computing the cost for house i, color j, add the previous min only if it wasn't color j; otherwise use the second-min. This collapses the inner loop from k to 1.

Can I solve this with basic DP and still pass?+

Depends on the test constraints. If n and k are small (both under 200), the O(n*k^2) solution might squeeze through. But LinkedIn's test cases likely include larger inputs. The optimized O(n*k) approach is the safe bet.

Does this problem require both Array and Dynamic Programming knowledge?+

Dynamic Programming is the core skill. Array comes in because you're iterating and indexing the DP table and the cost matrix. Both topics are necessary but DP is the primary concept being tested.

Want the actual problem statement? View "Paint House II" 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.