# Unique Paths

Medium

## Question

There is a robot in a grid that can move only rightward or downward at any point in time.

Given the dimensions of the grid, return the number of possible unique paths that the robot can take to travel from the top-left corner to bottom-right corner of the grid.

Input: `rows = 3, cols = 2`

Output: `3`

From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:

- Right -> Down -> Down
- Down -> Down -> Right
- Down -> Right -> Down

Input: `rows = 3, cols = 7`

Output: `28`

There are 28 ways to reach from the top-left to bottom-right corner.

Input: `row = 1, cols = 5`

Output: `1`

There is only one way to go from the top-left corner to bottom-right corner.

## Clarify the problem

What are some questions you'd ask an interviewer?

## Understand the problem

What should we use for our base case? Assume we use rows and cols as the memoization state.

f(0, 0) = 1

f(0, col) = 1 and f(row, 0) = 1

f(0, 0) = 0

f(0, y) = 0 and f(x, 0) = 0

All test cases pass! 🎉

Time limit exceeded

InputExpected OutputActual Output

Standard OutputScroll down...

Login or signup to save your code.

## Uh oh... looks like you don't yet have access.

Not sure what this unlocks? Check out a free pattern section.