Minimize Malware Spread Problem

Minimize Malware Spread Problem — ExecCode Hard DSA Practice

Solve the Minimize Malware Spread problem on ExecCode. Free online hard DSA practice in DSU. Write and run code in Java, C++, Python — no signup required to run.

Problem description

Given an undirected network as an adjacency matrix and a list of initially infected nodes, remove exactly one infected node. After removal, malware spreads through connected components from the remaining infected nodes. Return the node whose removal minimizes the final number of infected nodes. If tied, return the smallest node index.

Examples

Input {"data": "4\n1 0 0 0\n0 1 0 0\n0 0 1 1\n0 0 1 1\n2\n0 3"}; Output 3. Input {"data": "3\n1 0 0\n0 1 0\n0 0 1\n1\n0"}; Output 0. Input {"data": "2\n1 0\n0 1\n2\n0 1"}; Output 0

Constraints

2 <= graph.length <= 300 graph[i][j] is 0 or 1 1 <= initial.length <= graph.length

Practice Minimize Malware Spread free on ExecCode. Browse DSA problems, topic map, and placement guides.