k colors. Prices differ: prices[i][c] is the cost of painting house i in color c.
No two neighboring houses may share a color. Return the lowest total cost of painting every house.
Try to stay within O(n·k), where n is the number of houses.prices=[[4, 1, 7], [2, 9, 3], [5, 1, 8]] → 4
House 0 in color 1 (1), house 1 in color 0 (2), house 2 in color 1 again (1): 4 in total, and no two neighbors match.
prices=[[1, 2], [1, 2], [1, 2]] → 4
Color 0 is cheaper, but neighbors cannot match: 1 + 2 + 1 = 4.
prices=[[6, 3, 9, 2]] → 2
prices) ≤ 100prices[i]) ≤ 20, all rows have the same lengthprices[i][c] ≤ 20prices=[[4, 1, 7], [2, 9, 3], [5, 1, 8]]
4
Run checks the first 3 tests in your browser. Submit checks all 59 tests on the server, hidden ones included.