FastPrepReport Island Areas in Discovery Order
Problems/Report Island Areas in Discovery Order

Report Island Areas in Discovery Order

Snap Inc. logoSnap Inc.● MediumFULLTIMEPHONE SCREEN

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Snap Inc. phone screen. The report asks you to return every island area, with islands linked in four directions, and talks about finding the maximum area. It does not give an order for the result or the rules at the edges. Here areas come back in the order islands are found, row by row. The maximum is the largest returned value, or zero when the array is empty.

Given a rectangular binary matrix grid, return the area of every island.

An island is a maximal group of cells containing 1 connected horizontally or vertically. Its area is its number of cells.

Scan cells in row-major order, from top to bottom and left to right. When an unvisited land cell starts a new island, append that island's area to the result. Return an empty array when the grid contains no land.

Function

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

Examples

Example 1

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

The scan first reaches the three-cell island in the upper-left, then the three-cell island in the lower-right.

Example 2

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

The two one-cell islands are discovered before the three-cell island in the bottom row.

Example 3

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

The grid contains no land, so there are no island areas to report.

Constraints

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

More Snap Inc. interview questions

  • ID Allocator with Assign and ReleasePHONE SCREEN · Seen Nov 2026
  • Basic Calculator IIPHONE SCREEN · Seen Oct 2026
  • Stream Cluster Max and MedianPHONE SCREEN · Seen Oct 2026
  • LRU Cache with Thread-Safety Follow-UpPHONE SCREEN · Seen Sep 2026
  • Smallest Range Covering Elements from K ListsPHONE SCREEN · Seen Sep 2026
  • Most Stones Removed with Same Row or ColumnPHONE SCREEN · Seen Sep 2026
  • Render an Org Chart and Find Skip-Level PairsONSITE INTERVIEW · Seen Nov 2026
  • Peak of an Increasing-Then-Decreasing ArrayONSITE INTERVIEW · Seen Oct 2026
  • Number of Closed IslandsONSITE INTERVIEW · Seen Oct 2026
  • Radar Barrier CrossingONSITE INTERVIEW · Seen Oct 2026

Similar questions at other companies

  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Maximum Damage PatchGecko Robotics · OA · PHONE SCREEN
  • 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
  • Query Whether an Island Size ExistsMeta · ONSITE INTERVIEWMeta 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

Snap Inc. interview experiences

  • Snap Experienced MLE Onsite Interview Questions: 1 Experience
  • Snap AI Coding Interview, Experienced SWE and MLE: 4 Experiences
  • Snap Experienced MLE Virtual Onsite: 1 Experience
All Snap Inc. interview questionsSee Snap Inc. hiring insights
Saved
class Solution {
    public int[] islandAreas(int[][] grid) {
        // Write your code here.
    }
}
Checking account…