Query Whether an Island Size Exists
Updated
Problem statement
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]The island sizes are 3, 2, and 1.
Example 2
grid = [[1,0],[0,1]]queries = [1,2]return = [true,false]Diagonal land cells form two separate islands of size 1.
Example 3
grid = [[0,0],[0,0]]queries = [0,1]return = [false,false]There are no islands; size 0 is not an island size.
Constraints
gridis rectangular and may be empty.- Every grid cell is either
0or1. - 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