Unique Paths - Problem
There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]).
The robot tries to move to the bottom-right corner (i.e., grid[m - 1][n - 1]). The robot can only move either down or right at any point in time.
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.
The test cases are generated so that the answer will be less than or equal to 2 * 10^9.
Input & Output
Example 1 — Small Grid
$
Input:
m = 3, n = 7
›
Output:
28
💡 Note:
Robot needs 2 down moves and 6 right moves. Total arrangements: C(8,2) = 8!/(2!×6!) = 28 unique paths.
Example 2 — Square Grid
$
Input:
m = 3, n = 3
›
Output:
6
💡 Note:
Robot needs 2 down and 2 right moves. Arrangements: C(4,2) = 6. Paths: RRDD, RDRD, RDDR, DRRD, DRDR, DDRR.
Example 3 — Single Row
$
Input:
m = 1, n = 5
›
Output:
1
💡 Note:
Only one path possible: move right 4 times (RRRR) since we're already in the correct row.
Constraints
- 1 ≤ m, n ≤ 100
- The answer will be less than or equal to 2 × 109
Visualization
Tap to expand
Understanding the Visualization
1
Input
Grid dimensions m=3, n=3
2
Process
Robot can only move right or down
3
Output
Count all possible unique paths
Key Takeaway
🎯 Key Insight: This is a combinatorics problem - we're arranging a fixed number of moves in different orders
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code