Loading...
Loading...
Loading...
A map has land cells (1) and water cells (0). A patch is a group of land cells joined by a shared side (up, down, left or right). Print the number of patches.
Example
Input
4 5 11000 11010 00100 00011
Output
4
Cells that only touch at a corner are different patches.
Try the problem first. Open one hint at a time.
Scan the cells. At a land cell you have not seen, count one patch.
Then search from it and mark every land cell of that patch.
Write your Python code, run it on the examples and submit it to hidden tests.
Solve in the editor