Dsa
Union Find
Medium
Capacitated Infrastructure
You are managing a set of N infrastructure nodes, each with a specific data capacity. You want to merge nodes into clusters using links. However, two clusters can only be merged if the sum of their total capacities does not exceed a safety limit K. If a proposed link connects two clusters that would exceed K, the link is ignored. Given the initial capacities and a list of M proposed links, find the final number of disjoint clusters.
Example:
Input:
4 3 50
10 20 30 40
0 1
2 3
0 2
Capacities: [10, 20, 30, 40], K=50.
Link 0-1: 10+20=30 <= 50 (Success, 3 clusters).
Link 2-3: 30+40=70 > 50 (Ignored).
Link 0-2: 30+30=60 > 50 (Ignored).
Output: 3
Key concepts
union_findweight_constraintsgraph
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now