Unique Paths

Key Idea

Solution

class Solution:
    def uniquePaths(self, m: int, n: int) -> int:
        # Return the number of possible unique paths that the robot can take to reach the bottom right corner
        # Initialize the DP
        dp = [[1] * n for _ in range(m)]

        for i in range(1,m):
            for j in range(1,n):
                # Add
                dp[i][j] = dp[i-1][j] + dp[i][j-1]
        return dp[m-1][n-1]

Complexity