Unique Paths
1 approach, code in every language
Problem description
A robot starts in the top-left cell of an m x n grid. At every move it may step only one cell to the right or one cell down, and it is trying to reach the bottom-right cell.
Return how many distinct paths the robot can take to travel from the top-left corner to the bottom-right corner.
Example 1
Input: m = 3, n = 7
Output: 28
There are 28 unique right/down routes across a 3 by 7 grid.
Example 2
Input: m = 3, n = 2
Output: 3
From the top-left the robot can reach the bottom-right corner in exactly three ways.
Constraints
1 <= m, n <= 100
Create a free account to see the solution
You get the step-by-step animation, the intuition and clean code in every language. Free, no credit card.
After the pattern
Now solve one you haven't seen.
Grid Courier Routes is our own problem on the technique behind Unique Paths: a new statement, so there's no answer to remember. Write it in your browser and run it against graded tests.
1,194 problems · 15,062 graded tests · free