Loading repovive.com/problems/faang/3
This problem is based on an Amazon interview problem described here.
You are given an m×n grid where each cell contains either a zombie (1) or a human (0).
Every hour, all zombies simultaneously infect their adjacent humans. A zombie can infect the human directly up, down, left, or right of it (not diagonally).
Return the number of hours until no humans remain on the grid, or −1 if it is impossible (i.e., there are humans but no zombies to infect them).
ans
4 5 0 1 1 0 1 0 1 0 1 0 0 0 0 0 1 0 1 0 0 0
2
2 2 1 0 0 1
1
3 3 1 0 0 0 0 0 0 0 0
Thus it takes 4 hours
4