✅ Easy BFS solution | Python
Code\n\nfrom collections import deque\nclass Solution:\n    def containVirus(self, isInfected: List[List[int]]) -> int:\n        rows = len(isInfected)\n       
# Code\n```\nfrom collections import deque\nclass Solution:\n    def containVirus(self, isInfected: List[List[int]]) -> int:\n        rows = len(isInfected)\n        col = len(isInfected[0])\n\n        # get all the contaminated cells present using BFS\n        def getContaminatedArea():\n            infectedAreas = []\n            toBeInfectedAreas = []\n            walls = []\n            visited = [[False] * col for _ in range(rows)]\n\n            for r in range(rows):\n                for c in range(col):\n                    infectedArea = []\n                    toBeInfectedArea = set()\n                    wall = 0\n                    queue = deque()\n                    if isInfected[r][c] == 1 and not visited[r][c]:\n                        queue.append((r,c))\n                        infectedArea = [(r,c)]\n                        visited[r][c] = True\n                        while queue:\n                            popr, popc = queue.popleft()\n                            moves = [[1,0], [-1,0], [0,1], [0,-1]]\n                            for move in moves:\n                                if rows > popr + move[0] >= 0 and col > popc + move[1] >= 0:\n                                    if isInfected[popr + move[0]][popc + move[1]] == 1 and not visited[popr + move[0]][popc + move[1]]:\n                                        queue.append((popr + move[0], popc + move[1]))\n                                        visited[popr + move[0]][popc + move[1]] = True\n                                        infectedArea.append((popr + move[0], popc + move[1]))\n                                    elif isInfected[popr + move[0]][popc + move[1]] == 0:\n                                        toBeInfectedArea.add((popr + move[0], popc + move[1]))\n                                        wall += 1\n                        infectedAreas.append(infectedArea)\n                        toBeInfectedAreas.append(toBeInfectedArea)\n                        walls.append(wall)\n            return infectedAreas, toBeInfectedAreas, walls\n        \n        ## Spread the virus after each successful iteration of building walls\n        def spreadVirus(spreadingAreas):\n            for area in spreadingAreas:\n                for cell in area:\n                    isInfected[cell[0]][cell[1]] = 1\n\n\n        def no_of_elements_in_2d_list(list_2d):\n            return sum(len(li) for li in list_2d)\n\n\n        infectedAreas, toBeInfectedAreas, walls = getContaminatedArea()\n        wallCount = 0\n        while infectedAreas:\n            mostInfectedIndex = 0\n\n            totalInfectedCells = 0\n            for i in range(len(infectedAreas)):\n                totalInfectedCells += len(infectedAreas[i])\n\n            if totalInfectedCells == rows * col:\n                return wallCount\n\n            for i in range(len(toBeInfectedAreas)):\n                if len(toBeInfectedAreas[i]) > len(toBeInfectedAreas[mostInfectedIndex]):\n                    mostInfectedIndex = i\n            \n            for index in infectedAreas[mostInfectedIndex]:\n                isInfected[index[0]][index[1]] = -1\n            \n            wallCount += walls[mostInfectedIndex]\n            \n            spreadVirus(toBeInfectedAreas[:mostInfectedIndex] + toBeInfectedAreas[mostInfectedIndex + 1:])\n\n            infectedAreas, toBeInfectedAreas, walls = getContaminatedArea()\n        \n        return wallCount\n\n```
['Array', 'Breadth-First Search', 'Matrix', 'Simulation', 'Python3']