Search⌘ K
AI Features

Shortest Distance from All Buildings

Understand how to apply breadth-first search in grids to find the optimal empty land placement that minimizes total distance to all buildings. Learn to handle obstacles and buildings to calculate shortest paths efficiently, preparing you to solve similar coding interview problems involving grid traversal and distance optimization.

Statement

Given an m x n integer grid grid, where each cell contains one of three values:

  • 00 represents empty land that can be freely traversed,

  • 11 represents a building that cannot be passed through,

  • ...