C++ DFS Solution
```\nclass Solution {\n    int dx[4]={-1, 1, 0, 0}, dy[4]={0, 0, 1, -1};\npublic:\n    void dfs(int x, int y, vector>&grid, int &num, int &count, int &n, int &m
```\nclass Solution {\n    int dx[4]={-1, 1, 0, 0}, dy[4]={0, 0, 1, -1};\npublic:\n    void dfs(int x, int y, vector<vector<int>>&grid, int &num, int &count, int &n, int &m){\n        if(x<0 || x>=n || y<0 || y>=m || grid[x][y]!=1){\n            return;\n        }\n        grid[x][y]=num;\n        count++;\n        for(int i=0;i<4;i++){\n            dfs(x+dx[i], y+dy[i], grid, num, count, n, m);\n        }\n    }\n    \n    int largestIsland(vector<vector<int>>& grid) {\n        unordered_map<int,int>mp;\n        int n=grid.size(), m=grid[0].size();\n        int count, num=2;\n        int ans=0;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(grid[i][j]==1)\n                {\n                    //assign a number to each island and then assign number to each node of island\n                    //store the count for each island number\n                    count=0;\n                    dfs(i, j, grid, num, count, n, m);\n                    mp[num]=count;\n                    num++;\n                    ans=max(ans, count);\n                }\n            }\n        }\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(grid[i][j]==0){\n                    int island1=(i>0 && grid[i-1][j]? grid[i-1][j]: -1);\n                    int island2=(i<n-1 && grid[i+1][j]? grid[i+1][j]: -1);\n                    int island3=(j>0 && grid[i][j-1]? grid[i][j-1]: -1);\n                    int island4=(j<m-1 && grid[i][j+1]? grid[i][j+1]: -1);\n                    int sum=0;\n                    if(island1!=-1)\n                        sum+=mp[island1];\n                    if(island2!=-1 && island2!=island1){\n                        sum+=mp[island2];\n                    }\n                    if(island3!=-1 && island3!=island1 && island3!=island2){\n                        sum+=mp[island3];\n                    }\n                    if(island4!=-1 && island4!=island1 && island4!=island2 && island4!=island3){\n                        sum+=mp[island4];\n                    }\n                    sum++;\n                    ans=max(ans, sum);\n                }\n            }\n        }\n        return ans;\n    }\n};
[]