A robot is located at the top-left corner of a m x n grid.
The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid.
How many possible unique paths are there?
Note
m and n will be at most 100.
Example
No.1
Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
- Right -> Right -> Down
- Right -> Down -> Right
- Down -> Right -> Right
No.2
Input: m = 7, n = 3
Output: 28
Code
1 | // O(mn) runtime, O(mn) space – Bottom-up dynamic programming |