22 / 75
M

Unique Paths

#22
dynamic-programmingmathcombinatorics

Count unique paths from top-left to bottom-right in m×n grid moving only right/down.

Example:

Input:m=3, n=7
Output:28

Common 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