MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / searchGrid

Function searchGrid

javascript/0994-rotting-oranges.js:15–31  ·  view source on GitHub ↗
(grid, orangeCount = 0, queue = new Queue([]))

Source from the content-addressed store, hash-verified

13};
14
15const searchGrid = (grid, orangeCount = 0, queue = new Queue([])) => {
16 const [rows, cols] = [grid.length, grid[0].length];
17
18 for (let row = 0; row < rows; row++) {
19 /* Time O(ROWS) */
20 for (let col = 0; col < cols; col++) {
21 /* Time O(COLS) */
22 const isEmpty = grid[row][col] === 0;
23 if (!isEmpty) orangeCount++;
24
25 const isRotten = grid[row][col] === 2;
26 if (isRotten) queue.enqueue([row, col]); /* Space O(ROWS * COLS) */
27 }
28 }
29
30 return { queue, orangeCount };
31};
32
33const bfs = (grid, queue, rottenCount = 0, minutes = 0) => {
34 while (!queue.isEmpty()) {

Callers 1

orangesRottingFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected