This practice workspace is built for desktop. Open it on a larger screen to start solving.
Paint House
There are n houses in a row. Each house can be painted one of 3 colors: red, blue, or green. The cost of painting house i with color j is costs[i][j].
Adjacent houses cannot have the same color. Return the minimum total painting cost.
DP recurrence: for each house i and color j, the minimum cost is costs[i][j] + min(costs[i-1][other colors]).
Examples
Constraints
- costs.length == n
- costs[i].length == 3
- 1 <= n <= 100
- 1 <= costs[i][j] <= 20
Preview Mode
This is a read-only preview of DSAMind's AI coaching. Sign up to get custom feedback on your own solution.
Your approach
- Pattern:Dynamic Programming
- Time:O(N)
- Space:O(1)
Complete approach — pattern and complexity both named.
Coach
What you got right
You correctly matched the sorted input requirement and implemented a linear-time scan using two pointers.
Where it diverged
No divergence detected. The code correctly aligns with the stated approach.
Next attempt: focus on
Try solving related sliding window problems to build familiarity with two-pointer variants.
Signals
No signals fired — clean run, you stayed in flow.