Sponsored
Use these hints if you're stuck. Try solving on your own first.
Use Dynamic programming.
Define dp[i][j][k] as the minimum cost where we have k neighborhoods in the first i houses and the i-th house is painted with the color j.
Solve with full IDE support and test cases