Shortest Source to Destination Path
source link: https://www.geeksforgeeks.org/videos/shortest-source-to-destination-path-1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Shortest Source to Destination Path
In this video, we are given a 2D binary matrix A(0-based index) of dimensions NxM. We have to find the minimum number of steps required to reach from (0,0) to (X, Y).
Note: You can only move left, right, up, and down, and only through cells that contain 1.
Example :
Input:
N=3, M=4
A=[[1,0,0,0],
[1,1,0,1],
[0,1,1,1]]
X=2, Y=3
Output:
5
Explanation:
The shortest path is as follows:
(0,0)->(1,0)->(1,1)->(2,1)->(2,2)->(2,3).
Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/shortest-source-to-destination-path3544/1
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK