FastPrepLargest Island After One Land Conversion
Problems/Largest Island After One Land Conversion

Largest Island After One Land Conversion

Google logoGoogle● HardNEW GRADONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The interview report points to the well-known problem Making A Large Island. Our version keeps its rules exactly: a square binary grid, islands that join in four directions, and at most one conversion.

You are given an n x n binary matrix grid. You may change at most one 0 into 1.

An island is a group of 1 cells connected by moving up, down, left, or right through other 1 cells. Return the largest island area obtainable after the optional conversion.

Function

largestIsland(grid: int[][]) → int

Examples

Example 1

grid = [[1,0],[0,1]]return = 3
grid
01010101

Changing either zero joins the two diagonal land cells through the converted cell.

Example 2

grid = [[1,1],[1,0]]return = 4
grid
01011110

Changing the only zero makes the whole grid one island.

Example 3

grid = [[1,1],[1,1]]return = 4
grid
01011111

The grid is already one island, so no conversion is needed.

Constraints

  • 1 <= n <= 500.
  • n == grid.length == grid[i].length.
  • grid[i][j] is 0 or 1.
  • Four-directional adjacency defines an island.

More Google Onsite Interview questions

  • Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
  • Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
  • Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
  • Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
  • Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
  • Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026

Similar questions at other companies

  • Making a Large IslandMeta · ONSITE INTERVIEWMeta interview questions
  • Connected GroupsFivetran · ONSITE INTERVIEWFivetran interview questions
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Connected GroupsVisa · OAVisa interview questions
  • Count Islands in a GridDoorDash · PHONE SCREENDoorDash interview questions
  • Count Islands from Streaming RowsAmazon · ONSITE INTERVIEW
  • Longest Decreasing Matrix Path with Limited RelaxationsDuolingo · ONSITE INTERVIEWDuolingo interview questions
  • Largest Island After One Land ConversionBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Number of IslandsIntuit · ONSITE INTERVIEWIntuit interview questions

Interview reports that mention this question

  • Google PhD AI/ML New Grad Coding Onsite: 1 Experience

Google interview experiences

  • Google interviews · November 2026
  • Google Software Engineer Onsite Questions: 10 Experiences
  • Google OA: What It Tests (2026)
  • Google L4 SWE Phone Screen: 1 Experience
  • Google ML Engineering Manager Onsite: 1 Experience
All Google interview questionsSee Google hiring insights
Saved
class Solution {
    public int largestIsland(int[][] grid) {
        // Write your code here.
    }
}
Checking account…