Unique Paths

Try to solve the Unique Paths problem.

Statement#

Imagine a scenario where an adventurous little robot, named Robi, has a mission to traverse a grid with m rows and n columns and reach a treasure box placed at grid[m1][n1]grid[m-1][n-1]. Robi starts the journey from its home in the top-left corner of the grid, grid[0][0]grid[0][0]. However, it faces a constraint that at any given time, it can only move in either of the two directions: downward or to the right.

Given the two integers, m and n, return the total number of unique paths that Robi can take from the grid's top-left corner to reach the bottom-right corner of the grid.

Constraints:

  • \leq mn \leq 100

Example#

canvasAnimation-image

1 of 4

canvasAnimation-image

2 of 4

canvasAnimation-image

3 of 4

canvasAnimation-image

4 of 4

Understand the problem#

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:

Unique Paths

1

What will be the output if the following values of input are given?

mm = 2

nn = 2

A)

1

B)

2

C)

3

D)

4

Question 1 of 30 attempted

Try it yourself#

Implement your solution in the following coding playground:

The optimal solution to this problem runs in O(m x n) time and takes O(m x n) space.

Python
usercode > main.py
Input #1
Input #2
Unique Paths

You might want to go over the Dynamic Programming pattern again.

Solution: Partition Equal Subset Sum

Solution: Unique Paths