MediumMathDynamic ProgrammingCombinatorics

Unique Paths

LeetCode
1 approach, code in all languages

A robot starts in the top-left cell of an m x n grid. At every move it may step only one cell to the right or one cell down, and it is trying to reach the bottom-right cell.

Return how many distinct paths the robot can take to travel from the top-left corner to the bottom-right corner.

Example 1

Input: m = 3, n = 7

Output: 28

There are 28 unique right/down routes across a 3 by 7 grid.

Example 2

Input: m = 3, n = 2

Output: 3

From the top-left the robot can reach the bottom-right corner in exactly three ways.

Constraints

  • 1 <= m, n <= 100
You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.

750+ engineers trained · frontend, backend, AWS & AI

August 15 · 0d left
Enroll Now