Maximum Island Area
Updated
Problem statement
In the binary matrix grid, 1 represents land and 0 represents water. Land cells belong to the same island when they connect through shared sides. Diagonal contact does not join islands.
Return the greatest number of land cells in any one island. If the matrix contains no land, return 0. The area outside the matrix is water.
Function
maxAreaOfIsland(grid: int[][]) → intExamples
Example 1
grid = [[1,1,0],[0,1,0],[0,0,1]]return = 3The top-left island contains cells (0,0), (0,1), and (1,1), for area 3. Cell (2,2) forms a separate area-one island because it touches that island only diagonally.
Example 2
grid = [[0,0],[0,0]]return = 0Every cell is water, so there is no island and the answer is 0.
Constraints
1 <= grid.length <= 50.- Every row has the same length, from 1 to 50.
- Every cell is either 0 or 1.
More Intuit Online Assessment questions
- Employee Promotion OpportunitiesOA · Seen Oct 2026
- Next Pascal Row CoefficientOA · Seen Oct 2026
- Parse Router LogsOA · Seen Oct 2026
- Longest Repeated Letter Block with Adjacent SwapsOA · Seen Oct 2026
- Maximum Square-Free DivisorOA · Seen Oct 2026
- Two Tribes from Taller-Person CountsOA · Seen Oct 2026
- Shortest Path from an Encoded GraphOA · Seen Sep 2026
- Oldest and Youngest EmployeesOA · Seen Sep 2026
- Pressure-Isolation Shutdown OrderOA · Seen Sep 2026
- Submask Sum QueriesOA · Seen Sep 2026
Similar questions at other companies
- Minimum Cleaning Robot RunsHSBC · OAHSBC interview questions
- Count Islands with DFS and BFSVisa · OAVisa interview questions
- Number of IslandsGoldman Sachs · OA · PHONE SCREEN · ONSITE INTERVIEWGoldman Sachs interview questions
- House Bounds in a Ragged GridRippling · OA · PHONE SCREENRippling interview questions
- Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
- Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Shortest Bridge Between Two IslandsCompass International Holdings · ONSITE INTERVIEWCompass International Holdings interview questions
- Max Area of Island Without Changing the GridFlexport · PHONE SCREENFlexport interview questions
- Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
- Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions