A robot is located at the top-left corner of a m x n grid. The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid. How many possible unique paths are there?

Write a function to find the number of unique paths.

Function Signature:

def unique_paths(m: int, n: int) -> int:
    """
    Find the number of unique paths from the top-left corner to the bottom-right corner.

    Parameters:
    - m: Number of rows in the grid.
    - n: Number of columns in the grid.

    Returns:
    - int: Number of unique paths.
    """
    # Your code here

Example:

# Input: m = 3, n = 7
# Output: 28
# Explanation: There are 28 unique paths from the top-left corner to the bottom-right corner.

# Input: m = 3, n = 2
# Output: 3
# Explanation: There are 3 unique paths from the top-left corner to the bottom-right corner.

# Input: m = 2, n = 2
# Output: 2

# Input: m = 1, n = 1
# Output: 1

Note:

  • 1 <= m, n <= 100
  • It’s guaranteed that the answer will be less than or equal to 2 * 10^9.

Instructions:

  • Write the unique_paths function to solve the problem.
  • Implement your solution in Python.
  • Provide clear comments in your code.
  • Discuss the time and space complexity of your solution.

As always, we’ll share our solution to this problem tomorrow. Stay tuned 😊