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

Function dfs

javascript/0417-pacific-atlantic-water-flow.js:84–102  ·  view source on GitHub ↗
(row, col, rows, cols, isReachable, heights)

Source from the content-addressed store, hash-verified

82};
83
84const dfs = (row, col, rows, cols, isReachable, heights) => {
85 isReachable[row][col] = true;
86
87 for (const [_row, _col] of getNeighbors(row, rows, col, cols)) {
88 if (isReachable[_row][_col]) continue;
89
90 const isLower = heights[_row][_col] < heights[row][col];
91 if (isLower) continue;
92
93 dfs(
94 _row,
95 _col,
96 rows,
97 cols,
98 isReachable,
99 heights,
100 ); /* Space O(ROWS * COLS) */
101 }
102};
103
104var searchGrid = (
105 heights,

Callers 2

searchRowsFunction · 0.70
searchColsFunction · 0.70

Calls 1

getNeighborsFunction · 0.70

Tested by

no test coverage detected