Back to Question

Shortest Distance from All Buildings (BFS)

Question Explain

You are given a grid of 0s, 1s, and 2s. Find an empty land (0) that has the shortest total travel distance to all buildings (1s). This is a multi-source shortest path problem using BFS.

Start Trying This Question Simulation

Click "Start Speaking" and answer the question naturally.