Unique Paths - Problem
Robot Path Navigation Problem
Imagine a robot placed at the top-left corner of an
The robot has two movement constraints:
• It can only move right (→)
• It can only move down (↓)
Given the grid dimensions
Example: In a 3×7 grid, there are
🎯 Goal: Return the number of possible unique paths from top-left to bottom-right corner.
Imagine a robot placed at the top-left corner of an
m × n grid. This robot has a simple mission: navigate to the bottom-right corner using the most efficient path possible.The robot has two movement constraints:
• It can only move right (→)
• It can only move down (↓)
Given the grid dimensions
m (rows) and n (columns), your task is to calculate the total number of unique paths the robot can take to reach its destination.Example: In a 3×7 grid, there are
28 different ways to reach from (0,0) to (2,6).🎯 Goal: Return the number of possible unique paths from top-left to bottom-right corner.
Input & Output
example_1.py — Basic Grid
$
Input:
m = 3, n = 7
›
Output:
28
💡 Note:
In a 3×7 grid, the robot needs to make 2 down moves and 6 right moves (total 8 moves). The number of ways to arrange these moves is C(8,2) = 28.
example_2.py — Square Grid
$
Input:
m = 3, n = 2
›
Output:
3
💡 Note:
In a 3×2 grid, there are only 3 unique paths: right→down→down, down→right→down, and down→down→right.
example_3.py — Edge Case
$
Input:
m = 1, n = 1
›
Output:
1
💡 Note:
In a 1×1 grid, the robot is already at the destination, so there is exactly 1 path (staying put).
Visualization
Tap to expand
Understanding the Visualization
1
Start Position
Robot begins at top-left corner (0,0)
2
Movement Rules
Can only move right (→) or down (↓)
3
Path Counting
Each valid path requires exactly (m-1) down + (n-1) right moves
4
Mathematical Insight
Total paths = ways to arrange these moves = C(m+n-2, m-1)
Key Takeaway
🎯 Key Insight: This is fundamentally a combinatorial problem about arranging a sequence of moves, not a pathfinding problem!
Time & Space Complexity
Time Complexity
O(m*n)
We fill each cell in the m×n grid exactly once
✓ Linear Growth
Space Complexity
O(m*n)
We store the DP table of size m×n
⚡ Linearithmic Space
Constraints
- 1 ≤ m, n ≤ 100
- The answer will be less than or equal to 2 × 109
- All inputs are positive integers
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code