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
Open every published interview problem, solution, scene, and memory room free, with no account.