Unique Paths
Learn how to solve the 'Unique Paths' problem. This detailed resource details brute force and optimized approaches.
Problem Statement
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.
Write a function uniquePaths(m: int, n: int) -> int.
- •1 <= m, n <= 100
Examples
m = 3, n = 7
28
There are 28 unique paths to go from top-left to bottom-right.
m = 3, n = 2
3
From the top-left corner, there are 3 ways: Right -> Down -> Down, Down -> Down -> Right, or Down -> Right -> Down.
Need a Hint?
Edge Cases to Watch
- Empty list or null input variables
- Single item lists/arrays
- Extremely large input bounds causing integer or stack overflow
Ready to Solve?
Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.