Company: Netradyne__
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 rot 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. Function Description: You must implement the function minTimeToRottenOranges. 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 × M, where each element represents the state of an orange (0, 1, or 2) Returns: - int → The minimum time required to rot all fresh oranges - If it is impossible, return -1 Input Format: - First line: