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

Function bfs

javascript/0417-pacific-atlantic-water-flow.js:192–209  ·  view source on GitHub ↗
(heights, queue)

Source from the content-addressed store, hash-verified

190};
191
192const bfs = (heights, queue) => {
193 const [rows, cols] = [heights.length, heights[0].length];
194 const isReachable = getMatrix(
195 rows,
196 cols,
197 ); /* Time O(ROWS * COLS) | Space O(ROWS * COLS) */
198
199 while (!queue.isEmpty()) {
200 for (let i = queue.size() - 1; 0 <= i; i--) {
201 /* | Space O(WIDTH) */
202 const [row, col] = queue.dequeue();
203
204 checkNeighbor(heights, row, rows, col, cols, isReachable, queue);
205 }
206 }
207
208 return isReachable;
209};
210
211var getMatrix = (rows, cols) =>
212 new Array(rows)

Callers 1

pacificAtlanticFunction · 0.70

Calls 4

getMatrixFunction · 0.85
checkNeighborFunction · 0.70
isEmptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected