gary@interview:~/interview/coding/256-paint-house.md$
$ cat ./coding/256-paint-house.md
[Coding]

256. Paint House

────────────────────────────────────────────────────────────

256. Paint House

class Solution:
    def minCost(self, costs: List[List[int]]) -> int:
        if not costs:
            return 0
        n = len(costs)

        @cache
        def helper(i, prev):
            if i == n:
                return 0
            if prev == 0:
                return min(
                    costs[i][1] + helper(i + 1, 1),
                    costs[i][2] + helper(i + 1, 2),
                )
            elif prev == 1:
                return min(
                    costs[i][0] + helper(i + 1, 0),
                    costs[i][2] + helper(i + 1, 2),
                )
            elif prev == 2:
                return min(
                    costs[i][0] + helper(i + 1, 0),
                    costs[i][1] + helper(i + 1, 1),
                )
            else:
                return min(
                    costs[i][0] + helper(i + 1, 0),
                    costs[i][1] + helper(i + 1, 1),
                    costs[i][2] + helper(i + 1, 2)
                )
        
        return helper(0, float('inf'))
--tags#Dynamic Programming
$ ls ./coding/ | grep -v 256-paint-house
265. Paint House II143. Reorder List1762. Buildings With an Ocean View32. Longest Valid Parentheses
← cd ../codingcd ~