Dsa
Union Find
Easy
Electronic Circuit Connections
In designing an electronic circuit, components are connected via wires. Each connection is represented by pairs of components. Your task is to determine how many distinct subcircuits can be formed from a list of connections. A subcircuit is defined as a group of components that are interconnected directly or indirectly.
Input format:
- The first line contains an integer `c` (1 <= c <= 400) representing the number of connections.
- The next `c` lines each contain two alphanumeric characters representing the connected components (e.g., 'R1 R2').
Output format:
- A single integer representing the number of distinct subcircuits.
Example:
Input:
5
R1 R2
R2 R3
R4 R5
R6 R7
R8 R9
Output:
4
This means there are 4 distinct subcircuits: {R1, R2, R3}, {R4, R5}, {R6, R7}, and {R8, R9}.
Key concepts
union_finddesignelectrical
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