Count Storage Clusters After Each Replication Link Is Added
Last updated: November 29, 2026
Quick Overview
Given n storage nodes and a sequence of replication links being created between pairs of nodes, return the number of connected clusters after each link is added.
IBM
November 29, 20260
0
0 solved
Given n storage nodes and a sequence of replication links being created between pairs of nodes, return the number of connected clusters after each link is added.
IBM Storage products such as Storage Scale and FlashSystem replicate data between nodes, and tracking how clusters merge as links come up is a clean union-find question for storage and infrastructure teams. The interviewer checks that you use disjoint sets with path compression and union by rank instead of re-running BFS per event.
What the Interviewer Expects
- Recognize the online connectivity pattern as union-find
- Implement find with path compression
- Implement union by rank or size
- Decrement the component count only on a real merge
- Explain near-constant amortized cost
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 also report the size of the largest cluster after each event?
- What changes if links can also be removed?
- How would you detect the first link that creates a redundant loop?
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: integer n (nodes 0..n-1) and a list links of (a, b) pairs in creation order. Output: a list with the cluster count after each link. Duplicate links and links within an existing cluster ...
High-Level Design
Start with every node as its own set, so the count is n. For each link, find both roots. If they differ, attach the shorter tree under the taller one and decrement the count. Append the count after ...