• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
November 01, 2023 |550 Views
SDE Sheet - Shortest Source to Destination Path
Description
Discussion

This video is part of the Graph section under the GFG SDE Sheet.

In this problem, we are given, a 2D binary matrix A(0-based index) of dimensions NxM. 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).

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-
Article: https://www.geeksforgeeks.org/shortest-path-in-a-binary-maze/
Problem: https://practice.geeksforgeeks.org/problems/shortest-source-to-destination-path3544/1
SDE Sheet Link: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More