Count Delivery Clusters as New Drop Points Come Online
Last updated: November 29, 2026
Quick Overview
A city grid starts empty, and delivery drop points are activated one cell at a time; adjacent active cells (up, down, left, right) form one cluster. After each activation, return the current number of clusters.
Amazon
November 29, 20260
0
0 solved
A city grid starts empty, and delivery drop points are activated one cell at a time; adjacent active cells (up, down, left, right) form one cluster. After each activation, return the current number of clusters.
This is an online connectivity question framed around Amazon Logistics planning delivery zones as new Hub and Locker points open. Re-running a flood fill after each update is O(k * rows * cols); the interviewer wants an incremental union find.
What the Interviewer Expects
- Explain why repeated BFS is too slow
- Add each cell as a new component then union with active neighbors
- Decrement the count only on successful unions
- Handle duplicate activations
- O(k alpha(k)) time using only activated cells
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
- What if drop points can also be deactivated?
- How would you report the size of the largest cluster after each step?
- What if the grid is unbounded?
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) activations. Output: a list of cluster counts after each activation. Duplicate activations are allowed and change nothing....
High-Level Design
Keep a DSU only over active cells, stored in a dictionary so memory scales with activations, not the grid. When a cell turns on:
- If already active, append the current count.
- Otherwise add it as...