Hard · Matrices
Min Distance of Meeting Point
Given an m × n binary grid where each 1 marks a person’s home, return the minimum total Manhattan distance for all of them to walk to a single meeting cell, which may be any cell of the grid.
Examples
Example 1
{
"grid": [
[1, 0, 0],
[0, 0, 1],
[0, 1, 0]
]
}Output: min distance = 4
Example 2
{
"grid": [
[1, 0, 0, 0],
[0, 0, 0, 0],
[0, 0, 0, 1],
[1, 0, 1, 0]
]
}Output: min distance = 9
Rebuild it in the studio
Core interview problems are free with a full runner and lessons; Pro opens the complete library.