Solution to the following problem:
Given a matrix of 0s and 1s, where 0 represents water and 1 represents land, count the number of islands. Two pieces of land are connected if they are vertically or horizontally touching. Two pieces of land that are diagonal from each other are not touching.
e.g.:
Input
0 1 1 0 0 0 1
0 1 0 0 1 1 0
0 1 1 0 0 1 0
0 0 0 0 0 0 0
0 1 1 1 1 1 0
Output
4
-
pip install pandas
(only used for printing matrices) -
python island_counter.py