Back to problems

Find Shortest Path in Matrix

Algorithm · Meta · Medium

(This problem is adapted from LeetCode 1091, Shortest Path in Binary Matrix. If you haven’t solved that problem yet, it is advisable to complete it first.) Implement the function shortest_path_binary_matrix(n, grid) that finds the shortest path from the top‑left corner (0, 0) to the bottom‑right corner (m‑1, n‑1) of an $$m \times n$$ matrix of single digits. A cell containing a digit from 1 to 9 is traversable; a cell containing 0 is an obstacle and cannot be entered. From…

Checking your access…