Skip to main content

Unique Paths

MediumPremium

A robot is located at the top-left corner of an m x n grid (marked as (0, 0)).

The robot can only move either down or right at any point in time. The robot is trying to reach the bottom-right corner of the grid (marked as (m - 1, n - 1)).

Your task is to determine how many unique paths the robot can take to reach the destination.

Example

Input: m = 3, n = 3 Output: 6 S → □ → □ ↓ ↓ ↓ □ → □ → □ ↓ ↓ ↓ □ → □ → E

Explanation: Starting from the top-left corner S, you can move only right or down to reach the bottom-right corner E. There are 6 unique paths you can take:

Right → Right → Down → Down

Right → Down → Right → Down

Right → Down → Down → Right

Down → Right → Right → Down

Down → Right → Down → Right

Down → Down → Right → Right