A robot sits in the top-left cell of an m x n grid and wants to reach the bottom-right cell. It may only move right or down one cell at a time. Return how many distinct paths it can take.
Input / output
m: integer (rows), n: integer (columns)Examples
m = 3, n = 7 returns 28.m = 3, n = 2 returns 3.m = 1, n = 1 returns 1.Constraints
1 <= m, n <= 100Follow-up
Can you solve it in O(min(m, n)) space using the closed-form binomial coefficient C(m + n - 2, m - 1) instead of a full DP table?