← 返回 amazon 的题目列表Minimum Distance to Locker in a Grid
类型:online_judge
amazon
Given the size of a city and a list of locker locations within that city, calculate the minimum distance from each point to the nearest locker. The city is represented as an m x n grid, with each cell considered a location in the city. Locker locations are given as a list of 2D coordinates. Return a 2D array of size m x n representing the minimum distance from each city point to the nearest locker.
Example Input:
5 5
1 1
3 3
Example Output:
[[2, 1, 2, 3, 4],
[1, 0, 1, 2, 3],
[2, 1, 0, 1, 2],
[3, 2, 1, 0, 1],
[4, 3, 2, 1, 2]]
Constraints:
m, n >= 1
Number of lockers will not exceed m x n
Example
Input
5 5
1 1
3 3