MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / find_max_area

Function find_max_area

matrix/max_area_of_island.py:55–70  ·  view source on GitHub ↗

Finds the area of all islands and returns the maximum area. >>> find_max_area(matrix) 6

(mat: list[list[int]])

Source from the content-addressed store, hash-verified

53
54
55def 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
73if __name__ == "__main__":

Callers 1

Calls 1

depth_first_searchFunction · 0.70

Tested by

no test coverage detected