Dsa
Union Find
Medium
Secure Network Zones
In a computer network, nodes are either 'Encrypted' (type 1) or 'Plaintext' (type 0). A 'Secure Zone' is defined as a connected component of nodes where the number of Encrypted nodes is strictly greater than the number of Plaintext nodes. Given N nodes, their types, and M links added one by one, calculate the total number of Secure Zones remaining after all links are processed.
Example:
Input:
4 3
1 0 1 0
0 1
2 3
0 2
Initial: {0}(E), {1}(P), {2}(E), {3}(P). Secure: {0}, {2} (Total 2).
Link 0-1: {0,1} (1E, 1P) -> Not secure.
Link 2-3: {2,3} (1E, 1P) -> Not secure.
Link 0-2: {0,1,2,3} (2E, 2P) -> Not secure.
Final Secure Zones: 0
Key concepts
union_findattribute_trackinggraph
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