| 58 | }; |
| 59 | |
| 60 | var searchCols = (heights, rows, cols, pacificReachable, atlanticReachable) => { |
| 61 | for (let col = 0; col < cols; col++) { |
| 62 | /* Time O(COLS) */ |
| 63 | const [pacificStart, atlanticStart] = [0, rows - 1]; |
| 64 | |
| 65 | dfs( |
| 66 | pacificStart, |
| 67 | col, |
| 68 | rows, |
| 69 | cols, |
| 70 | pacificReachable, |
| 71 | heights, |
| 72 | ); /* Space O(ROWS * COLS) */ |
| 73 | dfs( |
| 74 | atlanticStart, |
| 75 | col, |
| 76 | rows, |
| 77 | cols, |
| 78 | atlanticReachable, |
| 79 | heights, |
| 80 | ); /* Space O(ROWS * COLS) */ |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | const dfs = (row, col, rows, cols, isReachable, heights) => { |
| 85 | isReachable[row][col] = true; |