FastPrepMaximum Area of an Island
Problems/Maximum Area of an Island

Maximum Area of an Island

Google logoGoogle● MediumNEW GRADPHONE SCREENONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: The firsthand report names the maximum island area as the medium question. We made it explicit that islands join in four directions and that the grid is not changed. Our version is about 94% the same as the reported question.

Given a rectangular binary grid, an island contains all 1 cells you can reach from one another by moving vertically or horizontally through land.

Return the largest island area, measured as its number of cells. Return 0 when the grid contains no land. Do not modify the input grid.

Function

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

Examples

Example 1

grid = [[0,0,1,0],[1,1,1,0],[0,1,0,0]]return = 5
grid
0123000101111020100

The central island contains five connected land cells.

Example 2

grid = [[0,0],[0,0]]return = 0
grid
01000100

There is no land.

Example 3

grid = [[1,0,1],[0,1,0],[1,0,1]]return = 1
grid
012010110102101

Diagonal cells are not connected, so every island has area one.

Constraints

  • 1 <= rows, columns <= 500.
  • Every cell is 0 or 1.

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

  • Number of IslandsFleetx · ONSITE INTERVIEW
  • Number of IslandsIntuit · ONSITE INTERVIEW
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
  • Shortest Bridge Between Two IslandsCompass International Holdings · ONSITE INTERVIEW
  • Max Area of Island Without Changing the GridFlexport · PHONE SCREEN
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEW
  • Number of Closed IslandsSnap Inc. · ONSITE INTERVIEW
  • Count Connected IslandsUber · PHONE SCREEN
  • Foreground Region SizesMicrosoft · ONSITE INTERVIEW
  • The MazeGoldman Sachs · ONSITE INTERVIEW
See Google hiring insights
Saved
class Solution {
    public int maxAreaOfIsland(int[][] grid) {
        // Write your code here.
    }
}
Checking account…