(grid, queue)
| 46 | }; |
| 47 | |
| 48 | var expireFresh = (grid, queue) => { |
| 49 | const [rows, cols] = [grid.length, grid[0].length]; |
| 50 | const [row, col] = queue.dequeue(); |
| 51 | |
| 52 | for (const [_row, _col] of getNeighbors(row, rows, col, cols)) { |
| 53 | const isFresh = grid[_row][_col] === 1; |
| 54 | if (!isFresh) continue; |
| 55 | |
| 56 | grid[_row][_col] = 2; |
| 57 | queue.enqueue([_row, _col]); /* Space O(ROWS * COLS) */ |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | var getNeighbors = (row, rows, col, cols) => |
| 62 | [ |
no test coverage detected