(matrix, row, rows, col, cols, ans = 0)
| 28 | }; |
| 29 | |
| 30 | var dfs = (matrix, row, rows, col, cols, ans = 0) => { |
| 31 | for (const [_row, _col] of getNeighbors(row, rows, col, cols)) { |
| 32 | /* Time O(4) */ |
| 33 | const path = dfs( |
| 34 | matrix, |
| 35 | _row, |
| 36 | rows, |
| 37 | _col, |
| 38 | cols, |
| 39 | ); /* Time O(2^(N + M)) | Space O(HEIGHT) */ |
| 40 | |
| 41 | ans = Math.max(ans, path); |
| 42 | } |
| 43 | |
| 44 | ans += 1; |
| 45 | return ans; |
| 46 | }; |
| 47 | |
| 48 | var getNeighbors = (row, rows, col, cols) => |
| 49 | [ |
no test coverage detected