Unique Paths Through a Grid
Problem statement
Given the number of rows m and columns n in a rectangular grid, count the distinct paths from the top-left cell to the bottom-right cell.
For this exercise, assume every cell is open and each move goes exactly one cell right or one cell down. Paths are distinct when their sequences of visited cells differ. Return the exact count as a 64-bit integer.
Function
uniquePaths(m: int, n: int) → longExamples
Example 1
m = 3n = 4return = 10Each path contains two down moves and three right moves. Choosing the two down positions among five moves gives 10 paths.
Example 2
m = 1n = 5return = 1There is only one row, so the only path moves right four times.
Constraints
- For this exercise, assume
1 <= m, n <= 20. - No blocked cells or other movement directions are part of this exercise.
- The result fits in a signed 64-bit integer.