Loading section...
2D DP: Grid Problems
Concepts: py2DDP, pyGridDP, pyRollingRow
Grid DP problems give you an m x n grid and ask you to move from top-left to bottom-right (usually only right or down). dp[i][j] represents 'the answer at cell (i, j).' Because you can only move right or down, dp[i][j] depends only on dp[i-1][j] (came from above) and dp[i][j-1] (came from left). Fill the table row by row, left to right. This structure is so regular that once you have solved unique paths, minimum path sum falls out in minutes. Unique Paths (LeetCode 62) Count the number of distinct paths from top-left to bottom-right of an m x n grid, moving only right or down. dp[i][j] = number of ways to reach cell (i,j). You reached (i,j) from (i-1,j) or (i,j-1). Recurrence: dp[i][j] = dp[i-1][j] + dp[i][j-1]. Base cases: first row and first column are all 1s (only one way to reach any c