
Calculate Islands
The Robots have found a chain of islands in the middle of the Ocean. They would like to explore these islands and have asked for your help calculating the areas of each island. They have given you a map of the territory. The map is a 2D array, where 0 is water, 1 is land. An island is a group of land cells surround by water. Cells are connected by their edges and corners. You should calculate the areas for each of the islands and return a list of sizes (quantity of cells) in ascending order. All of the cells outside the map are considered to be water.
Input: A map as a list of lists with 1 or 0.
Output: The sizes of island as a list of integers.
Example:
checkio([ [0, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 1, 0], [0, 1, 0, 0, 0], [0, 0, 0, 0, 0]]) == [1, 3] checkio([ [0, 0, 0, 0, 0], [0, 0, 1, 1, 0], [0, 0, 0, 1, 0], [0, 1, 1, 0, 0]]) == [5] checkio([ [0, 0, 0, 0, 0, 0], [1, 0, 0, 1, 1, 1], [1, 0, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0], [0, 1, 1, 1, 1, 0], [0, 0, 0, 0, 0, 0]]) == [2, 3, 3, 4]
How it is used: This task is an example of a disjoint-set data structure. Disjoint-set data structures model the partitioning of a set; for example, it helps with keeping track of the connected components in an undirected graph (networks).
Precondition:
0 < len(land_map) < 10
all(len(land_map[0]) == len(row) for row in land_map)
any(any(row) for row in land_map)
CheckiO Extensions allow you to use local files to solve missions. More info in a blog post.
In order to install CheckiO client you'll need installed Python (version at least 3.8)
Install CheckiO Client first:
pip3 install checkio_client
Configure your tool
checkio --domain=py config --key=
Sync solutions into your local folder
checkio sync
(in beta testing) Launch local server so your browser can use it and sync solution between local file end extension on the fly. (doesn't work for safari)
checkio serv -d
Alternatevly, you can install Chrome extension or FF addon
checkio install-plugin
checkio install-plugin --ff
checkio install-plugin --chromium
Read more here about other functionality that the checkio client provides. Feel free to submit an issue in case of any difficulties.