Count how many distinct ways there are to move from the top-left to the bottom-right of a grid using only right and down moves.
You are given two integers, and , describing an grid. A robot starts at the top-left cell and wants to reach the bottom-right cell.
At each step, the robot may move either one cell to the right or one cell down.
Return the number of distinct paths the robot can take to reach the destination.
Input Format
- Two integers and representing the number of rows and columns in the grid.
- The start is at cell and the destination is at cell .
Output Format
- Return a single integer: the total number of unique paths from start to finish.
Constraints
- The answer fits in a 32-bit signed integer for the standard problem formulation.
Example 1
Input
m = 3, n = 7
Output
28
Explanation
There are 28 different ways to move from the top-left corner to the bottom-right corner using only right and down moves.
Example 2
Input
m = 3, n = 2
Output
3
Explanation
The three paths are: Right → Down → Down, Down → Right → Down, and Down → Down → Right.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.