Grid-dp

7 articles

dsa1 min read

Unique Paths — Grid Path Count DP

Count paths from top-left to bottom-right moving only right or down. dp[i][j] = dp[i-1][j] + dp[i][j-1]. Math formula O(1) also works.

Read →
dsa1 min read

Minimum Path Sum — Grid DP

Find minimum cost path from top-left to bottom-right moving right or down. dp[i][j] = grid[i][j] + min(dp[i-1][j], dp[i][j-1]).

Read →
dsa1 min read

Triangle — Bottom-Up 1D DP

Minimum path sum from top to bottom of triangle. Bottom-up DP: dp[j] = triangle[i][j] + min(dp[j], dp[j+1]).

Read →
dsa1 min read

Dungeon Game — Reverse Grid DP

Find minimum initial health to reach bottom-right dungeon cell. Solve backwards: dp[i][j] = min health needed at (i,j) to survive.

Read →