Straight Forward Python Solution
\nclass Solution:\n    def containVirus(self, grid: List[List[int]]) -> int:\n\n        rows, cols = len(grid), len(grid[0])\n\n        def adj_cells(row, col):
```\nclass Solution:\n    def containVirus(self, grid: List[List[int]]) -> int:\n\n        rows, cols = len(grid), len(grid[0])\n\n        def adj_cells(row, col):\n            for r, c in [\n                (row + 1, col),\n                (row - 1, col),\n                (row, col + 1),\n                (row, col - 1),\n            ]:\n                if 0 <= r < rows and 0 <= c < cols:\n                    yield r, c\n\n        def no_of_elements_in_2d_list(list_2d):\n            return sum(len(li) for li in list_2d)\n\n        def get_contaminated_areas():\n            areas = []\n            dangers = []\n            walls = []\n            seen = [[False] * cols for i in range(rows)]\n\n            for r in range(rows):\n                for c in range(cols):\n                    if grid[r][c] == 1 and not seen[r][c]:\n                        area = [(r, c)]\n                        danger = set()\n                        queue = [(r, c)]\n                        seen[r][c] = True\n                        wall = 0\n\n                        while queue:\n                            m, n = queue.pop(0)\n                            for i, j in adj_cells(m, n):\n                                index = (i, j)\n                                if grid[i][j] == 1 and not seen[i][j]:\n                                    seen[i][j] = True\n                                    queue.append(index)\n                                    area.append(index)\n                                elif grid[i][j] == 0:\n                                    wall += 1\n                                    danger.add(index)\n                        areas.append(area)\n                        dangers.append(danger)\n                        walls.append(wall)\n\n            return areas, dangers, walls\n\n        def spread_virus(dangers):\n            for danger in dangers:\n                for row, col in danger:\n                    grid[row][col] = 1\n\n        wall = 0\n        areas, dangers, walls = get_contaminated_areas()\n\n        while areas:\n            area_count = len(areas)\n\n            if no_of_elements_in_2d_list(areas) == rows * cols:\n                return wall\n\n            dangerest_index = 0\n\n            for i in range(area_count):\n                if len(dangers[i]) > len(dangers[dangerest_index]):\n                    dangerest_index = i\n\n            wall += walls[dangerest_index]\n\n            for i, j in areas[dangerest_index]:\n                grid[i][j] = -1\n\n            spread_virus(dangers[:dangerest_index] + dangers[dangerest_index + 1 :])\n\n            areas, dangers, walls = get_contaminated_areas()\n\n        return wall\n```\n
['Breadth-First Search', 'Python3']