मुख्य कंटेंट तक स्किप करें
Back to ChallengesUnique PathsMedium 25 min

Unique Paths

There is a robot on an m x n grid. The robot is initially at the top-left corner (0, 0) and wants to move to the bottom-right corner (m - 1, n - 1). The robot can only move down or right. Return the number of possible unique paths.

Examples

Input: m = 3, n = 7
Output: 28
Total paths is 28.

Constraints

  • 1 <= m, n <= 100

Complexity Analysis

Time
O(m * n)
visiting each cell once.
Space
O(n)
only a single row tracker is needed.

Test Cases

#1 3x2 grid
Input: 3, 2
Expected: 3
#2 3x7 grid
Input: 3, 7
Expected: 28
#3 1x1 grid
Input: 1, 1
Expected: 1
JavaScript
Output
Click "Run Code" to see output here...