Largest Island
A map is given as a list of equal-length strings, one per row: # is land and . is water. Land cells that touch up, down, left or right belong to the same island; cells that only touch diagonally do not.
The size of an island is the number of land cells in it. Return the size of the largest island, or 0 if the map has no land.
Examples
["##...",
"#..##",
"...##",
"#...."] → 4
["....."] → 0
["#.#",
"###",
"..#"] → 6
["#.#.#"] → 1In the first example the islands have 3, 4 and 1 cells. In the third, all six land cells are joined.
Constraints
- Up to 100 rows and 100 columns; the map may be empty.
- Aim for O(n) in the number of cells: visit each cell a constant number of times.
Console
›Run to see what your code prints
Run checks the 4 visible cases here, in your browser. Submit runs all 9 on the judge, 5 of them hidden, and measures how your solution scales.
Expected is the reference solution's answer, from the judge. An input that breaks the statement's other rules may get any answer.