The Paint House IV problem gives you 2n houses and 3 colors. Each color has costs for houses 1..n and separately for houses n+1..2n (symmetric pairs). Adjacent houses (i and i+1) cannot share the same color. Find the minimum cost to paint all 2n houses. This is a 2-row variant of the standard paint house DP problem.
Chargebee, Amazon, and Bloomberg ask this because the two-row symmetric structure requires carefully linking the left and right halves of the house sequence. DP must handle the pairing constraint between symmetric house positions.
DP on paired positions. Process positions 1..n: for position i, house i has color c1 and house (2n-i+1) has color c2. Both c1 and c2 must differ from their respective neighbors, and the pair (c1,c2) must use different colors from each other. Track dp[i][c1][c2] = min cost for first i pairs. Transition: new pair (c1',c2') must have c1' ≠ prev c1 and c2' ≠ prev c2 and c1' ≠ c2'.
n=2, costs for positions (1,4)=(1,5), (2,3)=(2,3). 3 colors. Color constraints. Enumerate valid (c1,c2) pairs (where c1≠c2) for each position. Minimize total cost across all valid sequences.
Paint House variants test DP state design adaptability. When the problem adds structural constraints (pairs, symmetric positions, target neighborhoods), add the appropriate dimension to the DP state. Practice identifying what "additional history" each constraint requires and encoding it as an extra dimension. Paint House I→II→III→IV progressively adds dimensions, building strong DP design intuition.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Count Beautiful Splits in an Array | Medium | Solve | |
| Minimum Array Sum | Medium | Solve | |
| Last Stone Weight II | Medium | Solve | |
| Filling Bookcase Shelves | Medium | Solve | |
| Find the Maximum Length of Valid Subsequence I | Medium | Solve |