<jupyter_start><jupyter_text>USING DFS  This solution is concise but it is not the most efficient one since we might be computing many paths multiple times   This code gives correct answer but it was not accepted since the time limit got exceeded<jupyter_code>q = [
    [1,3,1],
    [1,5,1],
    [4,2,1]
]
def minPathSum(grid):
    def internal_path(matrix, row, col, nrow, ncol, sum_, arr):
        if (row == nrow and col == (ncol - 1)) or (col == ncol and row == (nrow - 1)):
            arr.append(sum_)
            return
        if row >= nrow or col >= ncol:
            return
        else:
            sum_ = sum_ + matrix[row][col]
            internal_path(matrix, row + 1, col, nrow, ncol, sum_, arr)
            internal_path(matrix, row, col + 1, nrow, ncol, sum_, arr)

    row, col = 0, 0
    nrow, ncol = len(grid), len(grid[0])        
    res = []
    internal_path(grid, row, col, nrow, ncol, 0, res)
    return min(res)
minPathSum(q)<jupyter_output><empty_output><jupyter_text>Using Dynamic programming  This is a efficient solution but it is not concise<jupyter_code>q = [
    [1,3,1],
    [1,5,1],
    [4,2,1]
]
def minPathSum(grid):
    dp = [[None for x in range(len(grid[0]))] for y in range(len(grid))] 
    
    m = len(grid) - 1 # row
    n = len(grid[0]) -1 # col
    
#     Populating last row
    for i in range(n, -1, -1):
        if i==n:
            dp[m][i] = grid[m][i]
        else:
            dp[m][i] = dp[m][i+1] + grid[m][i]
    
#     Populating last column
    for i in range(m-1, -1, -1):
        dp[i][n] = dp[i+1][n] + grid[i][n]
    
    for i in range(m-1, -1, -1):
        for j in range(n-1, -1, -1):
            dp[i][j] = min(dp[i][j+1], dp[i+1][j]) + grid[i][j]
#     print(dp)
    return dp[0][0]
minPathSum(q)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1564587973273942, 'fraction_numerical': 0.026169265033407572, 'mean_word_length': 2.340148698884758, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '279715', 'license': 'MIT', 'n_tokens_mistral': 704, 'n_tokens_neox': 687, 'n_words': 198, 'path': '064_Minimum_Path_Sum.ipynb', 'repo_name': 'NikhilAshodariya/LeetCode', 'size': '1796'}