Dsa
Union Find
Easy
Earthquake Network Resilience
During an earthquake, you need to assess the connectivity of different regions based on a series of reports about direct connections between them. Each connection signifies that the two regions can communicate directly. Your task is to find out how many independent groups of regions can still communicate with each other after processing all reports.
Input format:
- The first line contains an integer `r` (1 <= r <= 300), the number of reports.
- The next `r` lines each contain two uppercase letters representing the regions (e.g., 'P Q').
Output format:
- A single integer indicating the number of independent communication groups.
Example:
Input:
4
P Q
Q R
S T
U V
Output:
3
This means there are 3 independent groups of regions: {P, Q, R}, {S, T}, and {U, V}.
Key concepts
union_findnetworkconnectivity
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