928. Minimize Malware Spread II
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```python []
class Solution:
    def minMalwareSpread(self, graph, initial):
        def dfs(node, visited, infected, current_removal):
            visited[node] = True
            infected.add(node)
            for nei, is_connected in enumerate(graph[node]):
                if is_connected and not visited[nei] and nei != current_removal:
                    dfs(nei, visited, infected, current_removal)

        n = len(graph)
        initial.sort()
        min_infected = float('inf')
        result = initial[0]

        for node_to_remove in initial:
            visited = [False] * n
            total_infected = 0
            for node in initial:
                if node != node_to_remove and not visited[node]:
                    infected = set()
                    dfs(node, visited, infected, node_to_remove)
                    total_infected += len(infected)

            if total_infected < min_infected:
                min_infected = total_infected
                result = node_to_remove
            elif total_infected == min_infected and node_to_remove < result:
                result = node_to_remove

        return result

```
['Python']