Back to Practice Dashboard
Top 150 InterviewMedium

Unique Paths

Learn how to solve the 'Unique Paths' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Medium

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.

Constraints
  • 1 <= m, n <= 100

Examples

Example 1
Input
m = 3, n = 7
Output
28
Explanation

There are 28 unique paths to go from top-left to bottom-right.

Example 2
Input
m = 3, n = 2
Output
3
Explanation

From the top-left corner, there are 3 ways: Right -> Down -> Down, Down -> Down -> Right, or Down -> Right -> Down.

Need a Hint?
Define subproblem states, establish the recurrence relation, and use memoization (top-down) or tabulation (bottom-up).
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.

Open in Editor