Remove One Infected Server to Minimize Malware Spread
Last updated: November 29, 2026
Quick Overview
A network of n servers is given as an adjacency matrix. Malware starts on a list of initially infected servers and spreads to every server in the same connected component. You may clean exactly one initially infected server before spreading starts; return the one that minimizes the final infected count, choosing the smallest index on ties.
Meta
November 29, 20260
0
0 solved
A network of n servers is given as an adjacency matrix. Malware starts on a list of initially infected servers and spreads to every server in the same connected component. You may clean exactly one initially infected server before spreading starts; return the one that minimizes the final infected count, choosing the smallest index on ties.
A hard Meta onsite question in the style of security incident response across a server fleet. The interviewer checks the component-level insight: cleaning a server only helps when it is the sole infected node in its component, so union find with component sizes and infected counts settles it without simulating every choice.
What the Interviewer Expects
- Group servers into components with union find
- Count component sizes and initially infected per component
- Only components with exactly one infected node can be saved
- Pick the largest saved component, ties by smallest index
- Fall back to the smallest initial index if no removal helps
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How does the answer change if cleaning a server also removes it from the network?
- What if you can clean k servers?
- How would you handle spread that only succeeds with some probability per link?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
- Input:
graph, ann x nsymmetric 0/1 matrix, andinitial, the infected list. - Spread infects whole components that contain any infected node.
- Output: the index in
initialto clean....
High-Level Design
Removing a server from initial only changes the outcome for its own component:
- If that component has two or more initially infected servers, it still gets fully infected. No savings.
- If it has ...