Complete the code to initialize the DP table with zeros.
dp = [[[1] for _ in range(n)] for _ in range(m)]
We initialize the DP table with zeros to represent no paths counted yet.
Complete the code to set the number of paths for the first row.
for j in range(n): dp[0][j] = [1]
The first row cells can only be reached by moving right, so each has exactly 1 path.
Fix the error in the code to calculate paths for each cell.
for i in range(1, m): for j in range(1, n): dp[i][j] = dp[i-1][j] [1] dp[i][j-1]
Number of paths to a cell is sum of paths from top and left cells.
Fill both blanks to complete the function that returns unique paths.
def unique_paths(m, n): dp = [[0 for _ in range(n)] for _ in range(m)] for i in range(m): dp[i][[1]] = 1 for j in range(n): dp[[2]][j] = 1 for i in range(1, m): for j in range(1, n): dp[i][j] = dp[i-1][j] + dp[i][j-1] return dp[m-1][n-1]
First column (index 0) and first row (index 0) are set to 1 for base cases.
Fill all three blanks to create a dictionary comprehension for path counts with condition.
paths = [1]: [2] + [3] for i in range(m) for j in range(n) if i > 0 and j > 0
The keys are cell coordinates (i, j), and values are sum of paths from top and left neighbors.
