✅ C++ | CLEAN CODE | BFS
\nclass Solution {\npublic:\n    int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};\n    int walls=0;\n    \n    bool isValid(int i,int j,int m,int n,vector<vector<int>> &v
```\nclass Solution {\npublic:\n    int dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};\n    int walls=0;\n    \n    bool isValid(int i,int j,int m,int n,vector<vector<int>> &vis)\n    {\n        return (i>=0 && i<m && j>=0 && j<n && !vis[i][j]); \n    }\n    \n    int find(int i,int j,int m,int n,vector<vector<int>>& a)\n    {\n        int c=0;\n        \n        queue<pair<int,int>> q;\n        vector<vector<int>> vis(m,vector<int>(n,0));\n        \n        a[i][j]=2;\n        q.push({i,j});\n        \n        while(!q.empty())\n        {\n            i=q.front().first;\n            j=q.front().second;\n            q.pop();\n            \n            for(int k=0;k<4;k++)\n            {\n                if(isValid(i+dx[k],j+dy[k],m,n,vis))\n                {\n                    if(a[i+dx[k]][j+dy[k]]==0)\n                        c++;\n                    else if(a[i+dx[k]][j+dy[k]]==1)\n                    {\n                        a[i+dx[k]][j+dy[k]]=2;\n                        q.push({i+dx[k],j+dy[k]});\n                    }\n                                            \n                    vis[i+dx[k]][j+dy[k]]=1;\n                    \n                }\n            }\n        }\n        \n        return c;\n    }\n    \n    void putwalls(pair<int,int> &change,int m,int n,vector<vector<int>>& a)\n    {\n        int i,j;\n        i=change.first;\n        j=change.second;\n        \n        queue<pair<int,int>> q;\n        vector<vector<int>> vis(m,vector<int>(n,0));\n        \n        q.push({i,j});\n        \n        while(!q.empty())\n        {\n            i=q.front().first;\n            j=q.front().second;\n            a[i][j]=-1;\n            q.pop();\n            \n            \n            for(int k=0;k<4;k++)\n            {\n                if(isValid(i+dx[k],j+dy[k],m,n,vis))\n                {\n                    if(a[i+dx[k]][j+dy[k]]==2)\n                    {\n                        q.push({i+dx[k],j+dy[k]});\n                        a[i+dx[k]][j+dy[k]]=-1;\n                        vis[i+dx[k]][j+dy[k]]=1;    \n                    } \n                    else if(a[i+dx[k]][j+dy[k]]==0)\n                        walls++;\n                }\n            }\n        }\n    }\n    \n    void spread(int m,int n,vector<vector<int>>& a)\n    {\n        int i,j;\n        queue<pair<int,int>> q;\n        vector<vector<int>> vis(m,vector<int>(n,0));\n        \n        for(i=0;i<m;i++)\n        {\n            for(j=0;j<n;j++)\n            {\n                if(a[i][j]==2)\n                {\n                    a[i][j]=1;\n                    q.push({i,j});\n\n                }\n            }\n        }\n        \n        while(!q.empty())\n        {\n            i=q.front().first;\n            j=q.front().second;\n            q.pop();\n            \n            for(int k=0;k<4;k++)\n            {\n                if(isValid(i+dx[k],j+dy[k],m,n,vis) && a[i+dx[k]][j+dy[k]]==0)\n                {\n                    a[i+dx[k]][j+dy[k]]=1;\n                    vis[i+dx[k]][j+dy[k]]=1;     \n                }\n            }\n        }\n    }\n    \n    int containVirus(vector<vector<int>>& a) {\n        int m=a.size(),n=a[0].size();\n        int i,j;\n        \n        int infected=INT_MIN;\n        pair<int,int> change;\n        \n        while(infected!=0)\n        {\n            infected=0;\n            for(i=0;i<m;i++)\n            {\n                for(j=0;j<n;j++)\n                {\n                    if(a[i][j]==1)\n                    {\n                        int x=find(i,j,m,n,a);\n                        if(x>infected)\n                        {\n                            change={i,j};\n                            infected=x;\n                        }\n                    }\n                }\n            }\n            \n            if(infected!=0)\n            {\n                putwalls(change,m,n,a);\n                spread(m,n,a);\n            }\n        }\n        \n        return walls;\n    }\n};\n```\n\n**Do share your views & upvote if you like !!!** \uD83D\uDE0A
['Breadth-First Search', 'C', 'C++']