Start by clarifying the problem constraints (grid dimensions, obstacle representation, and whether the start/end can be blocked). Then explain a dynamic programming approach where dp[i][j] represents the number of paths to cell (i,j), computed from the top and left neighbors, with obstacles setting dp to 0. Finally, discuss time and space complexity and possible optimizations.
Pro tip: Mention that you can optimize space to O(n) by using a 1D DP array and updating it in place, and note that if the start or end is blocked, the answer is immediately 0.
Ask about grid size, obstacle representation, and whether the start or end can be blocked. Confirm that movement is only right and down.
Let dp[i][j] be the number of unique paths to cell (i,j). If the cell is blocked, dp[i][j] = 0; otherwise dp[i][j] = dp[i-1][j] + dp[i][j-1], with base case dp[0][0] = 1 if not blocked.
Iterate through the grid row by row, filling the DP table. Handle the first row and first column separately or initialize them appropriately.
State that time complexity is O(m*n) and space can be reduced from O(m*n) to O(n) by using a 1D array and updating it in place.
Walk through a small example, including cases with obstacles, blocked start/end, and a 1x1 grid.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.