Company: Amazon_31july
Difficulty: medium
Minimize Grid Inconvenience Problem Description A city is given as a grid. A cell marked 1 holds a delivery center; every other cell is marked 0 . The distance between two cells is the larger of the two coordinate gaps: the distance between cells (x1, y1) and (x2, y2) is max(|x1 - x2|, |y1 - y2|) . For example, the distance between (1, 2) and (0, 4) is max(|1 - 0|, |2 - 4|) = 2 . The inconvenience of the grid is the largest distance from any cell marked 0 to its nearest delivery center. You may open one new delivery center by converting at most one cell marked 0 into a 1 . Report the smallest inconvenience the grid can have afterwards. Function Description Complete the function getMinInconvenience . getMinInconvenience has the following parameter: grid : a 2D array of integers with n rows and m columns, every entry 0 or 1 Returns: an integer, the minimum inconvenience possible. Input Format The first line contains an integer n , the number of rows in the grid. The second line contains