Skip to content

Practice Making A Large Island

Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.

Hard#827
LeetCode Problem

Making A Large Island

Problem Statement

You are given an n x n binary matrix grid. You are allowed to change at most one 0 to be 1. Return the size of the largest island in grid after applying this operation. An island is a 4-directionally connected group of 1s.

Source: Making A Large Island on LeetCode. Use the original task for its coding environment and submissions.

Examples

# Example 1

Input
grid = [[1,0],[0,1]]
Output
3

# Example 2

Input
grid = [[1,1],[1,0]]
Output
4

# Example 3

Input
grid = [[1,1],[1,1]]
Output
4

Constraints

n == grid.length
n == grid[i].length
1 <= n <= 500
grid[i][j] is either 0 or 1.

Related LeetCode Problems

Practice more problems similar to Making A Large Island.

Review your practice with PhantomCodeAI

After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.