Unique Paths DP Visualizer

Link to the problem
Start Cell
End Cell
Current Cell
Checking Neighbors
Processed Cell
Unprocessed Cell
Rows
3
Columns
3
Speed
1

Python Implementation

1def unique_paths(n: int, m: int) -> int:
2 # Initialize dp table with zeros and set base case
3 dp = [[0] * m for _ in range(n)]
4 dp[0][0] = 1
5
6 # Fill dp table bottom-up
7 for i in range(n):
8 for j in range(m):
9 # Skip starting position
10 if i == 0 and j == 0:
11 continue
12
13 # Get paths from up and left
14 up = dp[i-1][j] if i > 0 else 0
15 left = dp[i][j-1] if j > 0 else 0
16 dp[i][j] = up + left
17
18 return dp[n-1][m-1]