// https://leetcode.com/problems/rotting-oranges/ import java.util.*; import java.io.*; class Main { static class Node{ int row; int col; int time; Node(int row, int col, int time){ this.row = row; this.col = col; this.time = time; } } public static int orangesRotting(int grid[][]) { int n = grid.length; int m = grid[0].length; Queue q = new LinkedList<>(); boolean visited[][] = new boolean[n][m]; // push all rotten orange sources for (int i=0; i= 0 && nc >= 0 && nr < n && nc < m && !visited[nr][nc] && grid[nr][nc] == 1){ grid[nr][nc] = 2; visited[nr][nc] = true; q.add(new Node(nr, nc, node.time + 1)); } } } for (int i=0; i