Practice Paint House IV
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
There are n houses in a line, where n is even, and cost[i][j] is the cost of painting house i with color j + 1 from three available colors. Adjacent houses must have different colors, and each mirrored pair i and n - 1 - i must also differ. Return the minimum total painting cost.
Source: Paint House IV on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
n = 4, cost = [[3,5,7],[6,2,9],[4,8,1],[7,3,5]]
Output
9
# Example 2
Input
n = 6, cost = [[2,4,6],[5,3,8],[7,1,9],[4,6,2],[3,5,7],[8,2,4]]
Output
18
Constraints
2 <= n <= 10^5
n is even.
cost.length == n
cost[i].length == 3
0 <= cost[i][j] <= 10^5
Related LeetCode Problems
Practice more problems similar to Paint House IV.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.