NeetCode #615LC-317HardGraphsNC Algo100
← Back to All Problems

#615 · #317 · Shortest Distance from All Buildings(离建筑物最近的距离)

📌 Problem Statement & Constraints

You are given an m x n grid where 0 is empty, 1 is a building and 2 is an obstacle. You want to build a house on an empty cell reachable from all buildings, minimising the total travel distance (Manhattan, avoiding obstacles). Return that minimum distance, or -1. Constraints: 1 <= m, n <= 50, at least one building.
🔒

Sign In to Unlock Full Solutions for All 973 Problems

Sign in to access step-by-step logic, benchmark Python3 code, complexity breakdown, and offline export!