matrix.max_area_of_island

Given an two dimensional binary matrix grid. An island is a group of 1’s (representing land) connected 4-directionally (horizontal or vertical.) You may assume all four edges of the grid are surrounded by water. The area of an island is the number of cells with a value 1 in the island. Return the maximum area of an island in a grid. If there is no island, return 0.

Attributes

matrix

Functions

depth_first_search(→ int)

Returns the current area of the island

find_max_area(→ int)

Finds the area of all islands and returns the maximum area.

is_safe(→ bool)

Checking whether coordinate (row, col) is valid or not.

Module Contents

Returns the current area of the island

>>> depth_first_search(0, 0, set(), matrix)
0
matrix.max_area_of_island.find_max_area(mat: list[list[int]]) int

Finds the area of all islands and returns the maximum area.

>>> find_max_area(matrix)
6
matrix.max_area_of_island.is_safe(row: int, col: int, rows: int, cols: int) bool

Checking whether coordinate (row, col) is valid or not.

>>> is_safe(0, 0, 5, 5)
True
>>> is_safe(-1,-1, 5, 5)
False
matrix.max_area_of_island.matrix = [[0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0], [0, 1, 1, 0,...