TV Tower Expansion
Problem statement
You are given a rectangular binary matrix city. A cell with value 1 initially contains a TV tower, and a cell with value 0 does not.
Each day, every cell containing a tower installs towers in its orthogonally adjacent cells: up, down, left, and right, when those cells are inside the matrix.
Return the number of days required for every cell to contain a tower. If the city has no initial tower, return -1.
Function
daysToCoverCity(city: int[][]) → intExamples
Example 1
city = [[1,0,0],[0,0,0]]return = 3The farthest cell is three orthogonal steps from the initial tower.
Example 2
city = [[1,0,1],[0,0,0],[0,1,0]]return = 1Every empty cell is adjacent to at least one of the three initial towers.
Example 3
city = [[1,1],[1,1]]return = 0The city is already fully covered.
Example 4
city = [[0,0],[0,0]]return = -1No initial tower exists, so expansion cannot begin.
Constraints
1 <= city.length <= 500.1 <= city[i].length <= 500.- Every row has the same length.
city[i][j]is0or1.