(matrix, row, rows, col, cols, memo)
| 92 | ); /* Time O(M) | Space O(M)*/ |
| 93 | |
| 94 | const search = (matrix, row, rows, col, cols, memo) => { |
| 95 | const hasSeen = memo[row][col] !== 0; |
| 96 | if (hasSeen) return memo[row][col]; |
| 97 | |
| 98 | return dfs( |
| 99 | matrix, |
| 100 | row, |
| 101 | rows, |
| 102 | col, |
| 103 | cols, |
| 104 | memo, |
| 105 | ); /* Time O(N * M) | Space O((N * M) + HEIGHT) */ |
| 106 | }; |
| 107 | |
| 108 | var dfs = (matrix, row, rows, col, cols, memo) => { |
| 109 | for (const [_row, _col] of getNeighbors(row, rows, col, cols)) { |
no test coverage detected