(row, col, rows, cols, isReachable, heights)
| 82 | }; |
| 83 | |
| 84 | const 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 | |
| 104 | var searchGrid = ( |
| 105 | heights, |
no test coverage detected