Count Provisioned Island Clusters After Each Azure Region Allocation

Last updated: November 29, 2026

Quick Overview

An R x C grid of map cells starts empty. Each operation provisions one cell as a datacenter site. After each operation, return the number of clusters, where a cluster is a set of provisioned cells connected four-directionally.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Onsite
Coding & Algorithms
Hard

0

0

0 solved


An R x C grid of map cells starts empty. Each operation provisions one cell as a datacenter site. After each operation, return the number of clusters, where a cluster is a set of provisioned cells connected four-directionally.

A dynamic connectivity Hard problem in the style of Microsoft onsites, framed around Azure capacity planning maps. Re-running BFS after each step is too slow, so the interviewer checks an online union find over grid cells, duplicate operation handling, and correct counting when one new cell merges several clusters.

What the Interviewer Expects
  • Map grid cells to integer ids
  • Add a new set for each provisioned cell and increment the count
  • Union with provisioned neighbors and decrement on each real merge
  • Ignore repeated provisioning of the same cell
  • Analyze O(k alpha(RC)) versus repeated BFS
Key Topics to Cover
union find
online connectivity
grids
amortized analysis
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you support decommissioning a cell?
  • How would you also report the size of the largest cluster after each step?
  • How would you shard this when the grid is a planet-scale map?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: R, C, and list ops of (r, c). Output: list of cluster counts, one per op. The same cell may appear more than once; re-provisioning does nothing and the count stays the same....

High-Level Design

Assign each cell id r * C + c. Keep a provisioned set and a union find over all R x C ids, created lazily or up front. For an operation on a new cell: add it, increment count because it starts a...


Submit Your Answer
Markdown supported