#3429
Paint House IV
specialist · 950 · lc medium +32 · 45.1% accepted · 121 likes · top 28%
Description
You are given an even integer n (the number of houses) and a 2D array cost of size n x 3, where cost[i][j] is the cost of painting house i with color j + 1.
The arrangement looks beautiful when:
- No two neighboring houses share the same color.
- Houses equidistant from the two ends of the row have different colors (e.g., for n = 6, houses at positions (0, 5), (1, 4), and (2, 3) must each differ).
Return the minimum cost to paint all houses such that the arrangement is beautiful.
Code
1
2
3