Untitled

 avatar
unknown
plain_text
19 days ago
770 B
3
Indexable
You are given an m x n grid where each cell can have one of three values:
 
0 representing an empty bed,
1 representing a non-infected patient, or
2 representing a infected patient.
Every minute, any non-infected patient that is 4-directionally adjacent to a infected patient becomes infected.
 
Return the minimum number of minutes that must elapse until all patients are infected. If this is impossible, return -1.
 
Ex1:
===
Input: grid = [[2,1,1],[1,1,0],[0,1,1]]
Output: 4
 
2 1 1
1 1 0
0 1 1
 
2 2 1
2 1 0
0 1 1
 
2 2 2
2 2 0
0 1 1
 
2 2 2
2 2 0
0 2 1
 
2 2 2
2 2 0
0 2 2
 
 
 
Example 2:
 
Input: grid = [[2,1,1],[0,1,1],[1,0,1]]
Output: -1
 
2 1 1
0 1 1
1 0 1
 
2 2 1
0 1 1
1 0 1
 
2 2 2
0 2 2
1 0 1
 
2 2 2
0 2 2
1 0 2
 
 
 
 
Input: grid = [[0,1]]
Output: -1
 
Editor is loading...
Leave a Comment