Given a 2D grid, each cell is either 1 or 0. Number 1 can turn adjacent (up/down/left/right) 0 into 1 every round.
Find out how many rounds does it take to turn the whole 2D grid 1?
Example :
Input:
[[0, 1, 1, 0, 1],
[0, 1, 0, 1, 0],
[0, 0, 0, 0, 1],
[0, 1, 0, 0, 0]]
Output:
2
Explanation:
At the end of the round 1, the status of the grid:
[[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[0, 1, 0, 1, 1],
[1, 1, 1, 0, 1]]
At the end of the round 2, the status of the grid:
[[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1]]
Copyright © A++ Code Bootcamp 2023