Count Land Masses as Satellite Tiles Arrive One by One
Last updated: November 29, 2026
Quick Overview
A rows by cols map starts as all water. Satellite processing marks tiles as land one at a time. After each arrival, report the number of islands, where an island is a group of land tiles connected horizontally or vertically.
0
0
0 solved
A rows by cols map starts as all water. Satellite processing marks tiles as land one at a time. After each arrival, report the number of islands, where an island is a group of land tiles connected horizontally or vertically.
Google Maps and Earth imagery pipelines update terrain incrementally, and this online version of island counting is a classic Google onsite. The interviewer wants union-find over cells with a running count, and checks for the duplicate-arrival bug and correct neighbor merges.
What the Interviewer Expects
- Explains why re-running BFS after each arrival is too slow
- Adds each new tile as its own set and increments the count
- Merges with land neighbors, decrementing on each real merge
- Handles duplicate arrivals without double counting
- Uses a sparse map so huge grids are fine
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Support tiles turning back into water.
- What if diagonal adjacency also counts?
- Report the size of the largest island after each step as well.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
rows,cols, and a list of(r, c)arrivals inside the grid. - Output: island count after each arrival.
- A repeated arrival changes nothing....
High-Level Design
Rerunning a flood fill after every arrival costs O(rows * cols) per step. Instead keep a union-find over land cells only. A new tile starts as its own island (count + 1). For each of its four neighbor...