📘
Unique Paths
MediumDynamic Programming
A robot on an m x n grid starts at top-left and can only move right or down. How many unique paths exist to the bottom-right?
Example:
Input:
3 7
Output:
28
Reasoning:
- The grid size is determined by the input values, with m=3 rows and n=7 columns.
- To reach the bottom-right corner, the robot must make m−1=2 moves down and n−1=6 moves right, for a total of m+n−2=8 moves.
- The number of unique paths is equivalent to choosing m−1=2 moves down out of the total 8 moves, which can be calculated using the binomial coefficient: (28)=2!(8−2)!8!=28⋅7=28.
- The final output is the result of this calculation, which represents the total number of unique paths to the bottom-right corner.
Constraints:
- 1 <= m, n <= 100
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.