Skip to content

Unique Paths

MediumDynamic Programming
Decode it first. Clues, constraints, pattern and plan before any code.

A robot starts in the top-left cell of an m × n grid and wants to reach the bottom-right cell. It can only move right or down. Return how many different paths it can take.

m = 3, n = 2  →  3   (right-down-down, down-right-down, down-down-right)
m = 3, n = 7  →  28
m = 1, n = 1  →  1

Constraints

  • 1 <= m, n <= 100
  • The answer is at most 2 * 10^9.