[00:01] is because it's really just one simple rule. You've got a row of houses to paint. Each one can be red, blue, or green. And each color has a different price at each house. The catch is that no two neighbors can [00:13] share a color. So, what's the cheapest way to paint them all? coloring. That's three to the end, which is dead on arrival. Instead, you need to the cheapest way to paint this house red?" Well, the house before it had to [00:27] cheaper of those two running totals and add today's red cost. Same for blue and green. That's the whole trick. Now, for every house, you build three answers. What's the best total cost if this house is red? Best total cost if [00:41] this house is blue? And the best total cost if this house is green? Let's trace the solution. Initialize your DP grid. The first row is just the costs. Green is the best choice for the second row with a cost of seven. For the [00:54] last row, blue is the best choice with a cost of 10. Each row only needs the one space. That's dynamic programming. You're not building the cheapest valid answer one house at a time. Well, here's a fun [01:07] optimize the space even further from linear to constant? Comment your answers below. And learn more with interactive visualizations at Hello Interview.