Company: urban_29july
Difficulty: medium
Rotten Oranges Problem Description You are given an N × M grid representing a storage area for oranges. Each cell in the grid can have one of the following values: 0 -- An empty cell 1 -- A fresh orange 2 -- A rotten orange A rotten orange at position (i, j) spreads to its adjacent fresh oranges (up, down, left, or right) every minute . The rotting process occurs simultaneously for all currently rotten oranges during each time step. Your task is to determine the minimum time required for all fresh oranges to become rotten. If at least one fresh orange cannot become rotten, return -1 . You must implement the function: int minTimeToRottenOranges(int N, int M, int[][] grid) . Parameters: Int N -- Number of rows in the grid Int M -- Number of columns in the grid Int [][] grid -- A 2D array of size N x M, where each element represents the state of an orange (0, 1, or 2) Input Format First line: One Integer N (number of rows) Second line: One Integer M (number of columns) Next N lines: Each