LC: 317. Shortest Distance from All Buildings - spiralgo/algorithms GitHub Wiki
317. Shortest Distance from All Buildings:
The Essence:
In order to find the tile with minimum distance, we need to count the distances to tiles.
We can count these distances by BFS'ing the whole grid at each building and summing up the tile distances in some matrix.
Let's assume that we have visited some tiles for some buildings. In some other building, if any tile around it can visit hasn't been visited by all the buildings before it, that means that there is no shortest distance for all buildings.
Details:
For a detailed explanation and implementation, please refer to the corresponding PR: