Returns the current area of the island >>> depth_first_search(0, 0, set(), matrix) 0
(row: int, col: int, seen: set, mat: list[list[int]])
| 31 | |
| 32 | |
| 33 | def depth_first_search(row: int, col: int, seen: set, mat: list[list[int]]) -> int: |
| 34 | """ |
| 35 | Returns the current area of the island |
| 36 | |
| 37 | >>> depth_first_search(0, 0, set(), matrix) |
| 38 | 0 |
| 39 | """ |
| 40 | rows = len(mat) |
| 41 | cols = len(mat[0]) |
| 42 | if is_safe(row, col, rows, cols) and (row, col) not in seen and mat[row][col] == 1: |
| 43 | seen.add((row, col)) |
| 44 | return ( |
| 45 | 1 |
| 46 | + depth_first_search(row + 1, col, seen, mat) |
| 47 | + depth_first_search(row - 1, col, seen, mat) |
| 48 | + depth_first_search(row, col + 1, seen, mat) |
| 49 | + depth_first_search(row, col - 1, seen, mat) |
| 50 | ) |
| 51 | else: |
| 52 | return 0 |
| 53 | |
| 54 | |
| 55 | def find_max_area(mat: list[list[int]]) -> int: |
no test coverage detected