Menu
CoddyTech

Unique Paths

A robot starts in the top-left cell of a grid with m rows and n columns and has to reach the bottom-right cell. Each move takes it one cell to the right or one cell down. Return the number of different paths it can take.

Function

uniquePaths(m: integer, n: integer) → integer
minteger
the number of rows in the grid
ninteger
the number of columns in the grid
Returnsinteger
the number of different paths from the top-left cell to the bottom-right cell

Constraints

  • 1 ≤ m, n ≤ 100
  • The answer is at most 2 × 109, so it fits in a signed 32-bit integer.

Examples

Input
m = 3n = 4
Output
10
Explanation
Every path makes 2 moves down and 3 moves right, 5 moves in all. A path is fixed by which 2 of the 5 moves go down, and there are 10 ways to pick them.
challenge icon

Follow-up

For a 100 × 100 grid the answer has 59 digits. How would you return it modulo 10^9+7 with the formula, when dividing by i no longer works?

Reset code
def uniquePaths(m, n):
    # Write code here

Test #1

Test #2

Test #3

Arguments

m = 3
n = 4

Expected Output

10