Dsa
Union Find
Hard
Corporate Monopoly Watch
A market has N companies (0 to N-1), each with an initial revenue. When two companies merge, they form a conglomerate with revenue equal to the sum of all its constituent companies. A conglomerate is considered a 'Monopoly' if its total revenue is at least R AND it contains at least M companies. You are given N, R, M, and the initial revenues. Then, Q merge operations follow. After each merge, output the current number of Monopolies in the market.
Example:
Input:
3 100 2
40 70 20
2
0 1
1 2
Output:
1
1
(After 1st merge: {0,1} has 110 rev and size 2. Monopoly! After 2nd: {0,1,2} has 130 rev and size 3. Still 1 monopoly).
Key concepts
union_findattribute_trackingdata_aggregation
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