Practice · Dynamic programming (2D) · 1 of 4

Count Paths Across a Grid

A robot stands in the top-left cell of a grid with m rows and n columns. Each move takes it one cell to the right or one cell down.

Return the number of different paths that take it to the bottom-right cell.

Example 1

Input
m = 2, n = 3
Output
3
Right, right, down; right, down, right; or down, right, right.

Example 2

Input
m = 3, n = 4
Output
10
Every path makes 2 moves down and 3 to the right, in some order.

Constraints

  • 1 ≤ m, n ≤ 100
  • The answer is less than 2³¹.
Brush up firstGrid Paths visualiser