Search⌘ K
AI Features

Shortest Distance from All Buildings

Explore how to apply Tree Breadth-First Search to find the optimal location in a grid for a new house by minimizing the sum of shortest distances to all buildings. Understand movement constraints, obstacle handling, and shortest path calculations to solve this common coding interview problem.

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,

  • ...