Grad shape
Grad shape

Unique Paths Containing No Obstruction

Get started
hero image
    🙏

    জয়  শ্রী  রাম

    🕉





Problem Statement:


A robot is located at the top-left corner of a m x n grid.
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.
Now consider if some obstacles are added to some cells in the grids. How many unique paths would there be?
An obstacle cell and a non-obstacle cell are marked as 1 and 0 respectively in the grid. The robot cannot move to a cell which has an obstacle placed in it.

Example 1:
Input: obstacleGrid = [[0,0,0],[0,1,0],[0,0,0]]
Output: 2
Explanation: There is one obstacle in the middle of the 3x3 grid above.
There are two ways to reach the bottom-right corner:
1. Right -> Right -> Down -> Down
2. Down -> Down -> Right -> Right

Example 2:
Input: obstacleGrid = [[0,1],[0,0]] Output: 1

Solution:


The solution for this problem is very similar to that of Unique Paths .
We have accounted for the obstacle in the code below to come up with the solution, re-using the code for Unique Paths.

Java Code:



Login to Access Content



Python Code:



Login to Access Content




Instructor: