Top 150 Interview

Unique Paths

Detailed guide and Python implementation for the 'Unique Paths' problem.

問題提起

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

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?
Consider using 2D DP-specific data structures like sets or heaps.
Edge Cases to Watch
  • Empty input structures
  • Single element inputs
  • Large numerical bounds

解決する準備はできましたか?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

エディタで開く
Found this breakdown helpful?

PyRun is built and maintained by an independent solo developer. If this helped your interview prep, consider buying a coffee!

Buy me a coffee

推奨される Python リソース

関連するインタラクティブなチュートリアル、チートシート、コード比較で知識を深めてください。