Problem · Hard · 35 min
Count the lakes
- Hard
- Grids
- Recursion
A map is a list of strings. All strings have the same length. In each string, "~" is water and "." is land.
A lake is a group of water cells that touch each other. Two cells touch when they are next to each other in the same row, or above each other in the same column. Cells that meet only at a corner do not touch.
Write count_lakes(grid). It returns the number of lakes on the map.
- An empty map has 0 lakes.
Examples
| Call | Result |
|---|---|
count_lakes(['~~..', '~...', '..~~']) |
2 |
count_lakes(['...', '...']) |
0 |
count_lakes(['~.~', '.~.', '~.~']) |
5 |
Tasks
2 to do
Task 1, not checked yet. Make
count_lakespass the example tests.Task 2, not checked yet. Make
count_lakespass the hidden tests.
Task 1 of 2
Make count_lakes pass the example tests.