Unique Paths

medium2-D Dynamic Programminggrid path-count DP (row-by-row)B75Solve on LeetCode#62

Part of Practice: Grids & Two Strings

A robot sits in the top-left corner of an m x n grid and wants to reach the bottom-right corner. On every move it can only go one cell right or one cell down — never left or up.

Count how many distinct paths exist from the top-left cell to the bottom-right cell.

Constraints: 1 <= m, n <= 100, and the answer is guaranteed to fit in a 32-bit integer.

Examples

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

Three paths: (right, down, down), (down, down, right), (down, right, down).

Input:
m = 2, n = 2
Output:
2

Either right-then-down or down-then-right.

Hints

One at a time — struggle first, peek second.

Your thinking space — verify on LeetCode, then mark it.