22 / 75
Medium
Unique Paths
#22dynamic-programmingmathcombinatorics
Count unique paths from top-left to bottom-right in m×n grid moving only right/down.
Example:
Input:
m=3, n=7Output:
28Common Mistakes:
- Not recognizing this is Pascal's Triangle pattern
- Using O(m*n) space when O(n) suffices with rolling array
- Not considering math solution: C(m+n-2, m-1)
Notes:
Mathematical solution: Choose m-1 downs from m+n-2 total moves = C(m+n-2, m-1). Time O(m*n) DP or O(min(m,n)) math, Space O(n) or O(1).
💻
Java Solution Hidden
Enable “Show Full Solution” to view the code
Count unique paths from top-left to bottom-right in m×n grid moving only right/down.
Example:
Input:
m=3, n=7Output:
28Common Mistakes:
- Not recognizing this is Pascal's Triangle pattern
- Using O(m*n) space when O(n) suffices with rolling array
- Not considering math solution: C(m+n-2, m-1)
Notes:
Mathematical solution: Choose m-1 downs from m+n-2 total moves = C(m+n-2, m-1). Time O(m*n) DP or O(min(m,n)) math, Space O(n) or O(1).
22/75
Unique Paths