Maximum Area of an Island
Updated
Problem statement
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[][]) → intExamples
Example 1
grid = [[0,0,1,0],[1,1,1,0],[0,1,0,0]]return = 5The central island contains five connected land cells.
Example 2
grid = [[0,0],[0,0]]return = 0There is no land.
Example 3
grid = [[1,0,1],[0,1,0],[1,0,1]]return = 1Diagonal cells are not connected, so every island has area one.
Constraints
1 <= rows, columns <= 500.- Every cell is
0or1.
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