prices[i][j] is the cost of painting house i in colour j (colours are numbered 0, 1, 2). Neighbouring houses must not have the same colour.
Return the minimum total cost of painting every house.prices=[[4, 9, 2], [3, 8, 5], [6, 1, 7]] → 6
Colour 3 for house 0 (2), colour 1 for house 1 (3), colour 2 for house 2 (1): 2 + 3 + 1 = 6.
prices=[[5, 1, 5], [5, 1, 5]] → 6
Colour 2 is cheapest for both houses, but neighbours cannot share it: 1 + 5 = 6.
prices=[[12, 3, 8]] → 3
prices=[[4, 9, 2], [3, 8, 5], [6, 1, 7]]
6
Run checks the first 3 tests in your browser. Submit checks all 85 tests on the server, hidden ones included.