You are given an n x n binary matrix grid. You may change at most one 0 to a 1. Return the size of the largest island in grid after applying this operation. An island is a group of 1s connected 4-directionally.
You are given an n x n binary matrix grid. You may change at most one 0 to a 1. Return the size of the largest island in grid after applying this operation. An island is a group of 1s connected 4-directionally.
Example 1:
Input: {"grid":[[1,0],[0,1]]}
Output: 3
Constraints:
n==grid.length
n==grid[i].length
1≤n≤500
grid[i][j] is either 0 or 1.
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"grid":[[1,0],[0,1]]}
The grid is 2 x 2 with 2 land cells. First give every island its own id (2, 3, ...) and record its area.