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

Function expireFresh

javascript/0994-rotting-oranges.js:48–59  ·  view source on GitHub ↗
(grid, queue)

Source from the content-addressed store, hash-verified

46};
47
48var 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
61var getNeighbors = (row, rows, col, cols) =>
62 [

Callers 2

bfsFunction · 0.85
orangesRottingFunction · 0.85

Calls 1

getNeighborsFunction · 0.70

Tested by

no test coverage detected