Count Account Clusters as Database Replication Links Are Added
Last updated: November 29, 2026
Quick Overview
Accounts in different regions are linked one pair at a time when a database is replicated between them. After each new link, report how many separate replication clusters exist, and at the end report the size of the largest cluster.
Snowflake
November 29, 20260
0
0 solved
Accounts in different regions are linked one pair at a time when a database is replicated between them. After each new link, report how many separate replication clusters exist, and at the end report the size of the largest cluster.
Snowflake replication and failover groups connect accounts across regions and clouds, and this incremental connectivity question shows up in online assessments. The grader looks for union find with path compression and union by size rather than rerunning BFS after every link.
What the Interviewer Expects
- Recognizes incremental connectivity and chooses union find over repeated BFS
- Implements path compression and union by size
- Decrements the component count only when two different roots merge
- Handles accounts that first appear inside a link
- States near-constant amortized cost per operation
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
- How would you support removing a replication link?
- How would you answer whether two accounts can fail over to each other in O(1) after building?
- How would you track the largest cluster after every link without scanning?
- What changes if links are directed, primary to secondary?
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: an initial list of accounts and a sequence of (a, b) links, which are undirected for clustering. Output: the number of clusters after each link and the largest cluster size at the end. Repeat...
High-Level Design
Each account starts as its own cluster. A link unions two sets; the cluster count drops by one only if the two accounts had different roots. Path compression flattens trees during find, and union by s...