Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Unique Path

Hard Acceptance 56.00% Points 40.00

You are given two integers m and n representing the number of rows and columns of a grid. A robot starts at the top-left cell (0, 0) and wants to reach the bottom-right cell (m-1, n-1).

The robot can only move:

Right (R)

Down (D)

Your task is to calculate the total number of unique paths the robot can take to reach the destination. Return the total number of possible paths.

Examples
Example 1

Example 1

Input: m = 1, n = 1

Output: 1

Explanation: The robot is already at the destination.

Example 2

Example 2

Input: m = 2, n = 2

Output: 2

Explanation: The robot can go Right?Down or Down?Right.

Example 3

Example 3

Input: m = 3, n = 3

Output: 6

Explanation: Different combinations of right and down moves lead to 6 distinct paths.

Hints
Hint 1
N/A
Constraints
  • 1 = m, n = 15
Companies
Amazon Microsoft Apple
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions