FastPrepQuery Whether an Island Size Exists
Problems/Query Whether an Island Size Exists

Query Whether an Island Size Exists

Meta logoMeta● MediumFULLTIMEONSITE INTERVIEW

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Meta onsite interview. The original report gives one-time work on island sizes up front, then queries that check in constant time whether a size exists. It does not say which cells touch or how to run a finite batch. Our version adds a usual batch form. It is about 94% the same as the reported question.

You are given a rectangular binary matrix grid and an integer array queries. A cell containing 1 is land and a cell containing 0 is water. Two land cells belong to the same island when they are connected through shared edges; diagonal contact does not connect islands.

Precompute the size of every island once. For each queries[i], return whether at least one island has exactly that many cells. Return the answers in query order.

Function

islandSizeExists(grid: int[][], queries: int[]) → boolean[]

Examples

Example 1

grid = [[1,1,0,0],[0,1,0,1],[1,0,0,1]]queries = [1,2,3,4]return = [true,true,true,false]
grid
0123011001010121001

The island sizes are 3, 2, and 1.

Example 2

grid = [[1,0],[0,1]]queries = [1,2]return = [true,false]
grid
01010101

Diagonal land cells form two separate islands of size 1.

Example 3

grid = [[0,0],[0,0]]queries = [0,1]return = [false,false]
grid
01000100

There are no islands; size 0 is not an island size.

Constraints

  • grid is rectangular and may be empty.
  • Every grid cell is either 0 or 1.
  • Every query is an integer.
  • The same precomputed set of sizes is used for every query.

More Meta Onsite Interview questions

  • Multi-Head Attention Forward PassPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Run-Length Encoded Vector Dot ProductPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Mutual-Friend RecommendationsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
  • Deterministic K-Means AssignmentsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
  • Linear Layer Forward and Backward PassesONSITE INTERVIEW · Seen Sep 2026
  • Reservoir Sampling with Recorded DrawsONSITE INTERVIEW · Seen Sep 2026
  • Stochastic Gradient Descent with MomentumONSITE INTERVIEW · Seen Sep 2026
  • Top K Largest Values with a HeapONSITE INTERVIEW · Seen Sep 2026
  • Partition a Card Deck into FifteensONSITE INTERVIEW · Seen Sep 2026
  • Insert into a Sorted Circular ListONSITE INTERVIEW · Seen Aug 2026

Similar questions at other companies

  • 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
  • Count Islands in a Binary GridApple · PHONE SCREENApple interview questions
  • Pacific Atlantic Water FlowAnduril · PHONE SCREENAnduril interview questions
  • Report Island Areas in Discovery OrderSnap Inc. · PHONE SCREENSnap Inc. interview questions
  • Generate All Contiguous Protein ChainsBenchling · PHONE SCREENBenchling interview questions

Interview reports that mention this question

  • Meta Software Engineer Onsite Questions: 3 Experiences

Meta interview experiences

  • Meta PhD SWE Intern AI Coding Phone Screen: 1 Experience
  • Meta Business Support Engineer Phone Screen: 1 Experience
  • Meta AI Native Engineer OA and Onsite: 1 Experience
  • Meta AI-Native Coding Interview: 3 Experiences
  • Meta Production Engineer Intern Questions: 6 Experiences
All Meta interview questionsSee Meta hiring insights
Saved
class Solution {
    public boolean[] islandSizeExists(int[][] grid, int[] queries) {
        // Write your code here.
    }
}
Checking account…