You are given a 2D array filled with 0
s and 1
s. You are allowed to switch at most one 0
to a 1
.
After performing this operation, determine the maximum size of a connected land area, where land area is defined as a group of 1
s connected vertically or horizontally.
Example 1: Input: [[1, 0], [0, 1]] Output: 3 Explanation: Change one zero to one to connect two separate lands, resulting in a land area of size 3.
Example 2: Input: [[1, 1], [1, 0]] Output: 4 Explanation: Changing the zero to one extends the land to size 4.
Example 3: Input: [[1, 1], [1, 1]] Output: 4 Explanation: No zeros to change, largest land is already of size 4.
0
or 1
.