prevMemo
to store the base case results for the first house.house
from 1 to m - 1
:
a. Create a new 2D array memo
to store the results for the current house.
b. For each neighborhoods
count and color
, calculate the minimum cost to paint the current house.
c. If the house is already painted with a different color, skip the iteration.
d. Otherwise, find the minimum cost by comparing the cost of painting the current house with the previous house's cost for different scenarios.
e. Update prevMemo
with the results from memo
.target
neighborhoods.target
neighborhoods.