Unique Paths
A robot stands in the top-left corner of a grid with m rows and n columns and has to reach the bottom-right corner. It can only step right or down. Count the different routes it can take. Our example: a 3 × 4 grid, 10 paths.
- input
m,n: the rows and the columns of a grid. A robot stands in its top-left corner and steps only right or down.- returns
- How many different routes take the robot to the bottom-right corner.
- constraints
- 1 ≤ m, n ≤ 100
- the answer is at most 2·10⁹
- examples
- Open a test in the tests panel: it shows the input and the expected answer.
/**
* @param {number} m
* @param {number} n
* @return {number}
*/
function uniquePaths(m, n) {
}
Ctrl ↵
format
reset
saved in this browser
Stuck?
See the solution run step by step on our example, then why it works and its complexity.
Next: more dynamic programming (dp) problems
- 70Climbing StairsEasysolve
- 121Best Time to Buy and Sell StockEasysolve
- 198House RobberMediumsolve
- 322Coin ChangeMediumsolve
- 300Longest Increasing SubsequenceMediumsolve
- 1143Longest Common SubsequenceMediumsolve
- 53Maximum SubarrayMediumsolve
- 918Maximum Sum Circular SubarrayMediumsolve
- 139Word BreakMediumsolve
- 120TriangleMediumsolve
- 64Minimum Path SumMediumsolve
- 63Unique Paths IIMediumsolve
- 97Interleaving StringMediumsolve
- 72Edit DistanceMediumsolve
- 221Maximal SquareMediumsolve
- 123Best Time to Buy and Sell Stock IIIHardsolve
- 188Best Time to Buy and Sell Stock IVHardsolve
The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.