Please use Laptop/Desktop or any other large screen for the Mock Interview Session.

Making A Large Island



YouTube Video Thumbnail
Link

Watch above sample mock interview video to see how it works.
Login and Buy Premium to Start the Interview



Problem Statement - Expanding Biggest Land

Expanding Biggest Land

Problem Statement

You are given a 2D array filled with 0s and 1s. 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 1s connected vertically or horizontally.

Examples

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.
    

Constraints

  • The grid is square with length between 2 and 60 inclusive.
  • Each element in the grid is either 0 or 1.