Skip to content

PRO TIP Block youtube.com at the DNS level — Pi-hole, NextDNS or your hosts file — but allow youtube-nocookie.com and i.ytimg.com. These tutorials keep playing; the rabbit hole does not.

Learning without distractions

DSA Python – Shortest Path in Binary Matrix | Leetcode 1091 | BFS Grid Traversal – Part 148 [Hindi]

1.7K views on YouTube

Welcome to Part 148 of Code & Debug’s DSA Python Course 2025!

In this video, we tackle Leetcode 1091 – Shortest Path in Binary Matrix, a classic BFS-based grid shortest path problem with 8-directional movement.

We use a distance matrix for relaxation and stop as soon as we reach the destination. This is a perfect example to understand how BFS can be extended to weighted-like logic without using Dijkstra or priority queue.

👨‍🏫 What’s covered in this video:
✅ Problem walkthrough and why normal DFS won’t work
✅ BFS grid traversal using a queue
✅ 8-directional movement from every cell
✅ Maintaining a distance matrix and relaxing distances
✅ Early exit when destination is reached
✅ Handling blocked starting and ending cells
✅ Python code walkthrough with dry run
✅ Time and Space Complexity Analysis

This problem is a great stepping stone for mastering grid-based BFS and pathfinding in constrained environments.

🔗 Leetcode 1091 – Shortest Path in Binary Matrix:
https://leetcode.com/problems/shortest-path-in-binary-matrix/description/

🔗 Code Reference for Path Reconstruction:
https://codeanddebug.in/blog/shortest-path-in-a-binary-matrix/

📄 Full Playlist Sheet (All Questions in Order):
https://docs.google.com/spreadsheets/d/1AWE15Fy3wD2iqu2vjK_R7cCiuvSsjYQclcdZmHpF66o/edit?usp=sharing

🎓 Enroll in the FREE Python DSA Course:
https://codeanddebug.in/course/master-dsa-with-leetcode

🚀 Master the Full DSA Track (Zero to Hero):
https://codeanddebug.in/course/zero-to-hero-python-dsa

Stay consistent and keep grinding with Code & Debug.
Like | Share | Subscribe & hit the bell icon for updates!

#ShortestPathBinaryMatrix #Leetcode1091 #GridBFS #Pathfinding #PythonDSA #DSA2025 #CodeAndDebug #Part148 #GraphTraversal #BinaryMatrixBFS