Making a Large Island
Given an n x n binary grid, you may change at most one 0 to a 1. Return the size of the largest island (a 4-directionally connected group of 1s) achievable after the change. If the grid is already all 1s, the whole grid is the island.
Open official problem prompt ↗Compute the maximum island size reachable by turning a single water cell into land, accounting for the merges that one flip can create.
Two neighboring plots of land separated by a thin canal: build one bridge tile across the canal and the plots become a single estate. You want the bridge that unites the largest combined estate.
- Input
- grid = [[1,0],[0,1]]
- Output
- 3
- Why
- Flipping the 0 at (0,1) connects the two size-1 islands into one island of size 3 (the flipped cell plus both original 1s).
n == grid.length == grid[i].length1 <= n <= 500grid[i][j] is 0 or 1