Rotten Oranges

Company: Netradyne__

Difficulty: medium

Problem Statement

Rotten Oranges Problem Description You are given an N x M grid representing a storage area for oranges. Each cell holds one of: 0 - an empty cell 1 - a fresh orange 2 - a rotten orange Every minute, each rotten orange spreads rot to the fresh oranges directly adjacent to it (up, down, left or right). The spreading happens simultaneously for all rotten oranges in each minute. Empty cells never rot and never pass rot along. Report the minimum number of minutes after which no fresh orange is left. If at least one fresh orange can never rot, report -1 . Function Description Implement the function minTimeToRottenOranges : int N : the number of rows int M : the number of columns int[][] grid : the N x M grid, each entry 0 , 1 or 2 The function returns an integer: the minimum number of minutes, or -1 if some fresh orange can never rot. Input Format For custom testing, standard input contains: Line 1: the integer N Line 2: the integer M Next N lines: M integers each, the rows of the grid Outpu