Dashboard
#59. Unique PathsMedium2-D Dynamic Programming

There is an m x n grid where you are allowed to move either down or to the right at any point in time.

Given the two integers m and n, return the number of possible unique paths that can be taken from the top-left corner of the grid (grid[0][0]) to the bottom-right corner (grid[m - 1][n - 1]).

You may assume the output will fit in a 32-bit integer.

Example 1:

Input: m = 3, n = 6

Output: 21

Example 2:

Input: m = 3, n = 3

Output: 6

Constraints:

  • 1 <= m, n <= 100
Examples
Example 1:
Input: m = 3, n = 6
Output: 21
Example 2:
Input: m = 3, n = 3
Output: 6
Constraints
  • `1 <= m, n <= 100`
Company Frequency
Amazon7Google5TCS5Goldman Sachs5Meta3Microsoft3LinkedIn3Flipkart3
Prerequisites
Target: O(N) time • O(1) spaceMath / Dynamic Programming / Combinatorics
Socratic AI Tutor
Gemini 3.8 Flash
Loading editor...

Click "Run" or press Ctrl+Enter to execute test cases.