FastPrepIsland Count and Maximum Area

Island Count and Maximum Area

Oracle logoOracleMediumFULLTIMEONSITE INTERVIEW
Learn

Problem statement

Given a rectangular binary matrix grid, find all islands. An island is a maximal group of 1 cells connected horizontally or vertically.

Return [islandCount, maximumArea]. The area of an island is its number of cells. Return [0,0] when the grid contains no land.

Function

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

Examples

Example 1

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

There are three islands; the island in the upper-left has area 3 and is the largest.

Example 2

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

No land cell exists.

Constraints

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

More Oracle problems

See Oracle hiring insights
public int[] islandStats(int[][] grid) {
    // Write your code here.
}
grid[[1,1,0,0],[0,1,0,1],[1,0,0,1]]
expected[3,3]
Checking account…