Unique Paths in a Grid
Given an MxN grid, count how many unique paths there are from the top-left corner to the bottom-right corner. You can only move either down or right at any point in time. The grid dimensions M and N will be provided as input.
[ 2, 3 ]
Explanation. The three paths are: right-right-down, right-down-right, down-right-right.
[ 3, 3 ]
Explanation. The paths include combinations of rights and downs three times each, but in different orders (e.g., DRR, RDR, RRD, DRRD, DRDR, DDRR).
[ 1, 1 ]
Explanation. The only path is to stay at the origin since you're already at the destination.
[ 7, 3 ]
Explanation. There are 28 unique ways to reach the bottom-right corner, which involves moving down 2 times and right 6 times in various orders.
Follow-up: Can you solve this problem using less than O(M*N) space?
1 \u2264 M, N \u2264 100
- Views
- 3