Infection in Wonderland

Company: Commvault_3sep

Difficulty: medium

Problem Statement

Infection in Wonderland Problem Description Wonderland is represented as a grid with R rows and C columns. The cell in the i -th row from the top and the j -th column from the left is called room (i, j) . Some rooms are initially infected. An infected room is shown as '#' and a non-infected (safe) room is shown as '.' . The infection spreads every minute. At each minute, every non-infected room that is adjacent (up, down, left or right) to an infected room becomes infected. All rooms that become infected during a minute do so at the same time, and they only start spreading the infection in the next minute. Your task is to determine the minimum time, in minutes, required for all rooms to become infected, so that no safe room remains in Wonderland. Complete the function minInfectionTime(R, C, grid) , which returns this number of minutes. Input Format Read from standard input. R C row_1 row_2 ... row_R The first line contains two space-separated integers R and C , the number of rows and c