Class Solution

  • All Implemented Interfaces:

    
    public final class Solution
    
                        

    928 - Minimize Malware Spread II.

    Hard

    You are given a network of n nodes represented as an n x n adjacency matrix graph, where the <code>i<sup>th</sup></code> node is directly connected to the <code>j<sup>th</sup></code> node if graph[i][j] == 1.

    Some nodes initial are initially infected by malware. Whenever two nodes are directly connected, and at least one of those two nodes is infected by malware, both nodes will be infected by malware. This spread of malware will continue until no more nodes can be infected in this manner.

    Suppose M(initial) is the final number of nodes infected with malware in the entire network after the spread of malware stops.

    We will remove exactly one node from initial, completely removing it and any connections from this node to any other node.

    Return the node that, if removed, would minimize M(initial). If multiple nodes could be removed to minimize M(initial), return such a node with the smallest index.

    Example 1:

    Input: graph = [1,1,0,1,1,0,0,0,1], initial = 0,1

    Output: 0

    Example 2:

    Input: graph = [1,1,0,1,1,1,0,1,1], initial = 0,1

    Output: 1

    Example 3:

    Input: graph = [1,1,0,0,1,1,1,0,0,1,1,1,0,0,1,1], initial = 0,1

    Output: 1

    Constraints:

    • n == graph.length

    • n == graph[i].length

    • 2 &lt;= n &lt;= 300

    • graph[i][j] is 0 or 1.

    • graph[i][j] == graph[j][i]

    • graph[i][i] == 1

    • 1 &lt;= initial.length &lt; n

    • 0 &lt;= initial[i] &lt;= n - 1

    • All the integers in initial are unique.

    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
    • Field Summary

      Fields 
      Modifier and Type Field Description
    • Constructor Summary

      Constructors 
      Constructor Description
      Solution()
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
    • Method Summary

      Modifier and Type Method Description
      final Integer minMalwareSpread(Array<IntArray> graph, IntArray initial)
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait