Paint House II

There is a row of n houses, where each house can be painted with one of k colors. The cost of painting each house with a certain color is represented by an n x k cost matrix costs.

Return the minimum cost to paint all houses such that no two adjacent houses have the same color.

The challenge is to solve this in O(n*k) time.

Examples
Input: [[1,5,3],[2,9,4]]
Output: 5
Hints

Paint House II

There is a row of `n` houses, where each house can be painted with one of `k` colors. The cost of painting each house with a certain color is represented by an `n x k` cost matrix `costs`.