Unique Paths

Medium#622d table

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⁹
our 13 tests keep to them
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

13 tests · limit 3 s

Stuck?

See the solution run step by step on our example, then why it works and its complexity.

Watch the walkthrough →

Next: more dynamic programming (dp) problems

Pattern “Dynamic programming (DP)” →

The problem and its statement belong to LeetCode. Here are our own retelling, example and solution. Patterns Hero is not affiliated with LeetCode.