Largest Island After One Land Conversion
Problem statement
Given a rectangular binary grid, you may change at most one 0 into 1. An island is a four-directionally connected group of ones. Return the largest island area obtainable after the optional conversion.
Function
largestIsland(grid: int[][]) → intExamples
Example 1
grid = [[1,0],[0,1]]return = 3Converting either zero joins both diagonal land cells through the converted cell.
Example 2
grid = [[1,1],[1,0]]return = 4Converting the only zero makes the complete grid one island.
Constraints
1 <= grid.length, grid[i].length <= 500grid[i][j] is 0 or 1four-directional adjacency defines an island