Finds the area of all islands and returns the maximum area. >>> find_max_area(matrix) 6
(mat: list[list[int]])
| 53 | |
| 54 | |
| 55 | def find_max_area(mat: list[list[int]]) -> int: |
| 56 | """ |
| 57 | Finds the area of all islands and returns the maximum area. |
| 58 | |
| 59 | >>> find_max_area(matrix) |
| 60 | 6 |
| 61 | """ |
| 62 | seen: set = set() |
| 63 | |
| 64 | max_area = 0 |
| 65 | for row, line in enumerate(mat): |
| 66 | for col, item in enumerate(line): |
| 67 | if item == 1 and (row, col) not in seen: |
| 68 | # Maximizing the area |
| 69 | max_area = max(max_area, depth_first_search(row, col, seen, mat)) |
| 70 | return max_area |
| 71 | |
| 72 | |
| 73 | if __name__ == "__main__": |
no test coverage detected