A robot moves only right or down on an m × n grid. How many paths lead from the top-left to the bottom-right cell?
Before you code
Each cell is entered from above or from the left, so its count is the sum of those two counts.
Hints
- Row 0 and column 0 are all 1.
dp[r][c] = dp[r-1][c] + dp[r][c-1].- One row is enough. The closed form is C(m + n − 2, m − 1).
Production & complexity notes
When solving Unique paths on LeetCode (medium), always state your loop or recursion invariant before writing code. Verify how your chosen data structure behaves on degenerate inputs (single-element inputs, all-duplicate keys, strictly monotonic sequences, or maximum constraint sizes up to $10^5$ elements). In production interviews, pair your implementation with an explicit time and auxiliary space complexity proof, explain why alternative brute-force approaches violate the latency budget, and trace how cache locality and memory allocation overhead affect wall-clock throughput on real hardware. Review the step-by-step memory trace in Grids and strings to reinforce the underlying pattern.
What it practices
Row-by-row grid tables, from Grids and strings.