Unique Paths

There is a robot on an m x n grid. The robot starts at the top-left corner of the grid and wants to reach the bottom-right corner.

At any point, the robot can move only in one of two directions:

  • Down
  • Right

Given the two integers m and n, return the number of possible unique paths that the robot can take to reach the bottom-right corner.

Example 1
Inputm = 3, n = 7
Output28
There are 28 distinct ways to move from the top-left corner to the bottom-right corner of a 3 by 7 grid.
Example 2
Inputm = 3, n = 2
Output3
From the top-left corner, the robot must make two downward moves and one rightward move, which can be arranged in 3 unique ways.

Constraints

  • 1 <= m, n <= 100
  • The answer will be less than or equal to 2 * 10^9

Asked at 22 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate