Shortest Distance from All Buildings

Given an m x n grid grid where:

  • 0 is an empty land cell;
  • 1 is a building;
  • 2 is an obstacle.

You can move only up, down, left, and right, and cannot pass through buildings or obstacle...

Example

Unlock to view complete problem details

and practice with sample input/output

Was this article helpful?

View Test Cases & Run Code requires membership

Standard Input
Execution Result: