Unique Paths in a Matrix with Obstacle | Recursive and Dynamic Programming Solution
00:00 - Overview 02:07 - State Space Tree 04:18 - Recursive derivation 11:54 -Overlapping Subproblem 13:00 - Dynamic Programming without obstacle 18:51 - Dynamic Programming with obstacle (Leetcode - 63) Problem Url : https://leetcode.com/problems/unique-paths-ii/ 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 the grids. How many unique paths would there be? An obstacle and empty space is marked as 1 and 0 respectively in the grid. Note: m and n will be at most 100. Example 1: Input: [ [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 Solution : We are first going to draw the state space tree for the provided matrix and then try to come up with recursive solution for the same, by breaking the problem into smaller subproblems. Now we'll find out the overlapping subproblem and save it in a solution matrix to cache the previously calculated result. Next time on we''ll use the previous values to compute next state.
Download
0 formatsNo download links available.