plan with m rows and n columns. A cell holds 1 if it is covered by forest and 0 if it is open field.
A forest patch is a group of forest cells linked through their top, bottom, left or right neighbours; touching diagonally does not join patches. There is no forest beyond the edges of the map.
The size of a patch is the number of cells in it. Return the size of the largest patch, or 0 if the map has no forest.plan=[[1, 1, 0, 0], [0, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 1]] → 4
There are three patches: three cells in the top-left corner, two cells at the bottom left and four cells on the right. The largest has 4 cells.
plan=[[1, 0, 1], [0, 1, 0], [1, 0, 1]] → 1
The cells touch only at the corners, so each one is a separate patch of size 1.
plan=[[0, 0], [0, 0]] → 0
There is no forest at all, so the answer is 0.
plan=[[1, 1, 0, 0], [0, 1, 0, 1], [1, 0, 0, 1], [1, 0, 1, 1]]
4
Run checks the first 3 tests in your browser. Submit checks all 62 tests on the server, hidden ones included.