Minimize Malware Spread
Try to solve the Minimize Malware Spread problem.
We'll cover the following
Statement#
You’re given a network of nodes as an adjacency matrix graph with the node directly connected to the node if graph[i][j] == 1.
A list of nodes, initial, is given, which contains nodes initially infected by malware. When two nodes are connected directly and at least one of them is infected by malware, both nodes will be infected by malware. This spread of malware will continue until every node in the connected component of nodes has been infected.
After the infection has stopped spreading, will represent the final number of nodes in the entire network that have been infected with malware.
Return a node from initial such that, when this node is removed from the graph, is minimized. If multiple nodes can be removed to minimize , return the node with the smallest index.
Note: If a node was removed from the initial list of infected nodes, it might still be infected later on due to the malware’s spread.
Constraints:
graph.length == graph[i].length- n
graph[i][j]is or .graph[i][j] == graph[j][i]graph[i][i] == 1-
initial.length -
initial[i] - All the integers in the
initialare unique.
Examples#
1 of 2
2 of 2
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Minimize Malware Spread
Given the following graph and the initially infected nodes, which node will help minimize the malware spread?
graph = [[1, 1, 1],
[1, 1, 0],
[1, 0, 1]]
initial = [1, 2]
0
1
2
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Implement your solution in main.py in the following coding playground. You will need the provided supporting code to implement your solution.
Solution: Last Day Where You Can Still Cross
Solution: Minimize Malware Spread