Given an r × c grid of 1 (land) and 0 (water), count the islands — groups of land connected horizontally or vertically.
Input
r cOutput: the number of islands.
4 5 1 1 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 0 0 0
1
4 5 1 1 0 0 0 1 1 0 0 0 0 0 1 0 0 0 0 0 1 1
3
Run your code against the sample tests, or Submit to run the full suite.