Shortest Path in Matrix

Algorithm · Meta · Medium

For an N-by-M grid containing blank cells, gates (G), and walls (W), replace every blank cell with its minimum number of steps to reach any gate. You may move only one cell at a time vertically or horizontally. Example Each numeric entry is the fewest up, down, left, or right moves needed to arrive at a gate; walls remain unchanged.

Loading the rest of the question…