Unique Paths
There is a robot on an `m x n` grid. The robot is initially located at the top-left corner (i.e., `grid[0][0]`). The robot tries to move to the bottom-right corner (i.e., `grid[m - 1][n - 1]`). The robot can only move either down or right at any point in time. Given the two integers `m` and `n`, return the number of possible unique paths that the robot can take to reach the bottom-right corner. **Examples:** ```typescript uniquePaths(3, 7) // 28 uniquePaths(3, 2) // 3 ```
Solve It in the BrowserPractice Explaining It Out Loud
Optimal Approach
- Time complexity: O(m * n)
- Space complexity: O(n)
Iterates through the m x n grid, computing cell transitions in O(1).
Follow-Up Questions Interviewers Ask About Unique Paths
- How to calculate this using combinatorics in O(m) time?
Total moves is (m - 1) + (n - 1). The answer is combinations C(m + n - 2, m - 1).
Practice the full problem with execution, tests, and AI code review in the interactive lab — then rehearse explaining your solution in a live voice mock interview.