Search⌘ K
AI Features

Shortest Distance from All Buildings

Explore how to use breadth-first search to find the shortest total travel distance from a house placed on empty land to all buildings in a grid. Learn to handle obstacles and buildings while optimizing placement. This lesson develops skills in spatial traversal and path calculation for coding interviews.

Statement

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

    ...