FastPrepMaximum Damage Patch
Problems/Maximum Damage Patch

Maximum Damage Patch

Gecko Robotics logoGecko Robotics● MediumNEW GRADOAPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Firsthand Gecko Robotics reports from August and September 2023 identify this as the Max Area of Island task recast as the largest orthogonally connected damage patch; the source screenshots provide the function contract and examples.

Given a rectangular binary matrix grid, return the maximum area of an island. An island is a maximal group of cells containing 1 connected horizontally or vertically. Its area is its number of cells.

Return 0 when the matrix contains no land.

Function

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

Examples

Example 1

grid = [[0,0,1,0],[1,1,1,0],[0,1,0,1]]return = 5
grid
0123000101111020101
Largest patch (5 cells)Other patches

The green region has 5 cells, so the answer is 5.

The center island contains five orthogonally connected land cells. The bottom-right cell is a separate island of area 1.

Example 2

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

There are no land cells.

Example 3

grid = [[0,0,1,1,0,1,0,0],[0,1,0,1,0,1,0,0],[1,1,0,1,0,1,0,0],[0,0,0,0,0,0,0,1]]return = 4
grid
01234567000110100101010100211010100300000001
Largest patch (4 cells)Other patches

The green region has 4 cells, so the answer is 4.

There are four islands. The largest has 4 cells: (0,2), (0,3), (1,3) and (2,3). The island (1,1), (2,0), (2,1) has 3 cells, the column (0,5), (1,5), (2,5) has 3 cells, and (3,7) is alone. Cells that touch only at a corner are not connected, so these islands do not join. The answer is 4.

Example 4

grid = [[0,0,0,1],[0,0,1,0],[0,1,0,0],[1,0,0,0]]return = 1
grid
012300001100102010031000
Largest patch (1 cell)Other patches

The green region has 1 cell, so the answer is 1.

The four land cells sit on a diagonal. Each pair touches only at a corner, so every cell is its own island of area 1.

Constraints

  • 1 <= grid.length, grid[i].length <= 300.
  • Every row has the same length.
  • grid[i][j] is either 0 or 1.

More Gecko Robotics Online Assessment questions

  • Generate Parameter CombinationsOA · PHONE SCREEN · Seen Sep 2023

Similar questions at other companies

  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Maximum Area of IslandSkydio · PHONE SCREENSkydio interview questions
  • Number of Islands with Diagonal ConnectivityGoogle · ONSITE INTERVIEWGoogle interview questions
  • Island Count and Maximum AreaOracle · ONSITE INTERVIEWOracle interview questions
  • Max Area of IslandGoldman Sachs · ONSITE INTERVIEWGoldman Sachs interview questions
  • Max Area of IslandRoku · ONSITE INTERVIEWRoku interview questions
  • Max Area of IslandBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
  • Maximum Area of IslandSambaNova Systems · ONSITE INTERVIEWSambaNova Systems interview questions
  • Number of IslandsAmazon · PHONE SCREEN · ONSITE INTERVIEW
See Gecko Robotics hiring insights
Saved
class Solution {
    public int maxIslandArea(int[][] grid) {
        // Write your code here.
    }
}
Checking account…