Virus Spread (Intuit India)
You are given a petri dish with a grid with some healthy cells at locations i,j. It is of dimensions N x M, where each grid point in the dish can only have the following values:
Unfortunately, a virus can make its healthy neighbors sick (infected), and you need to find the minimum time at which all the cells have the virus. A virus-cell at location [i, j] will infect healthy cells at [i-1, j], [i+1, j], [i, j-1], [i, j+1] (up, down, left and right), and this takes place in one second of time. If not all cells in the dish are infected with the virus, then return -1.
Complete the function minimumTimeToInfect in the editor.
minimumTimeToInfect has the following parameter:
int N: Num of rowsint M: Num of columnsReturns
int: an integer that denotes the min time for all cells to have the virus, or print -1 if not all cells in the dish are infected.
N = 2 M = 3 grid = [[2, 0, 0], [1, 1, 1]] return = 3
N = 2 M = 3 grid = [[2, 0, 1], [1, 1, 0]] return = -1
- 1 <= N <= 100
- 1 <= M <= 100
- 0 <= ar[j] <= 2
- Small Business Network: Degrees of SeparationPHONE SCREEN · Seen May 2026
- Set Total Palindrome Transformation CostSeen Feb 2026
- Smart Gardener (Intuit India)Seen Feb 2024
- Jumping Kady (Intuit India)Seen Feb 2024
- Longest Cipher (Intuit India)Seen Feb 2024
- Maximum Reward (Intuit India)Seen Feb 2024
- Spreading Fire (Intuit India)Seen Feb 2024
- Ice Cream SticksSeen Feb 2024
public int minimumTimeToInfect(int N, int M, int[][] grid) {
// write your code here
}