copy paste
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\n    class Region {\n        Set<Integer> infected = new HashSet<>();\n        Set<Integer> unInfected = new HashSet<>();\n        int walls = 0;\n    } \n    public int containVirus(int[][] isInfected) {\n        int ans = 0;\n        int re = isInfected.length;\n        int ce = isInfected[0].length;\n\n        while (true) {\n            List<Region> holder = new ArrayList<>();\n            boolean[][] v = new boolean[re][ce];\n            for (int r = 0; r < re; r++) {\n                for (int c = 0; c < ce; c++) {\n                    if (isInfected[r][c] == 1 && !v[r][c]) {\n                        Region region = new Region();\n                        getRegion(isInfected, region, re, ce, v, r, c);\n                        holder.add(region);\n                    }\n                }\n            }\n            int indexOfMaxUnInfected = 0;\n            int sizeOfMaxUnInfected = 0;\n            for (int i = 0; i < holder.size(); i++) {\n                Region region = holder.get(i);\n\n                if (region.unInfected.size() > sizeOfMaxUnInfected) {\n                    sizeOfMaxUnInfected = region.unInfected.size();\n                    indexOfMaxUnInfected = i;\n                }\n            }\n            if (holder.size() == 0) {\n                break;\n            }\n            Set<Integer> maxSet = holder.get(indexOfMaxUnInfected).infected;\n            for (int rowCol : maxSet) {\n                int r = rowCol / ce;\n                int c = rowCol % ce;\n                isInfected[r][c] = 2;\n            }\n            ans += holder.get(indexOfMaxUnInfected).walls;\n            for (int i = 0; i < holder.size(); i++) {\n                \n                if (i == indexOfMaxUnInfected) {\n                    continue;\n                }\n                Region region = holder.get(i);\n                Set<Integer> unInfected = region.unInfected;\n\n                for (int rowCol : unInfected) {\n                    int r = rowCol / ce;\n                    int c = rowCol % ce;\n                    isInfected[r][c] = 1;\n                }\n            }\n        }\n        return ans;\n    }\n    int[][] dirs = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};\n    private void getRegion(int[][] isInfected, Region region, int re, int ce, \n        boolean[][] v, int r, int c) {\n        if (r < 0 || c < 0 || r == re || c == ce || isInfected[r][c] == 2) {\n            return;\n        }\n        if (isInfected[r][c] == 1) {\n            if (v[r][c]) {\n                return;\n            }\n            region.infected.add(r * ce + c);\n        }\n        if (isInfected[r][c] == 0) {\n            region.unInfected.add(r * ce + c);\n            region.walls++;\n            return;\n        }\n        v[r][c] = true;\n        for (int[] dir : dirs) {\n            int nr = r + dir[0];\n            int nc = c + dir[1];\n            getRegion(isInfected, region, re, ce, v, nr, nc);\n        }\n    }\n}\n```
['Java']