Back to Questions

Shortest Distance from All Buildings (BFS)

133.3K viewsAsked at Meta
Hard

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

Practice answering orally or with text to get instant AI feedback.

Practice with This Question
Shortest Distance from All Buildings (BFS) - Interview Question