from utils.matrix import Matrix

class Solution:
    def min_path_sum(self, matrix):
        row_count, col_count = matrix.row_count, matrix.col_count

        if not row_count or not col_count:
            return 0
        
        sum_row = [float('inf') for _ in range(col_count + 1)]
        sum_row[1] = 0

        for row in range(1, row_count + 1):
            new_sum_row = [float('inf') for _ in range(col_count + 1)]
            for col in range(1, col_count + 1):
                new_sum_row[col] = matrix[row - 1][col - 1] + min(new_sum_row[col - 1], sum_row[col])
            sum_row = new_sum_row
        
        return sum_row[-1]

matrix = Matrix([[5,2,8],[6,1,0],[3,3,7]])
print(matrix)
solution = Solution()
print(solution.min_path_sum(matrix))

