Making A Large Island || simple DFS| | c++
| |Algorithm| |\n\n->first mark each and every island present initially with unique colors (this can be done using a simple dfs).\n->then iterate through every 
| |Algorithm| |\n\n->first mark each and every island present initially with unique colors (this can be done using a simple dfs).\n->then iterate through every index . if grid[i][j]==0 then we need to check if any of its 4 adjacent cells has grid[i][j]>0.\n->if grid[i][j] >0 then we increase our ans by hashmap[grid[i][j]] .doing this for all 4 adjacent cells we update our max ans every time.(hashmap stores the count of every color in their respective island).\n->return maxans\n\ncode in c++\n\n```\nclass Solution {\npublic:\n    int ans=0;\n    int dx[4]={1,-1,0,0};\n    int dy[4]={0,0,1,-1};\n    int visit[501][501];\n    map<int,int>mp;\n    int val=2;\n    int n;\n    void dfs(int x,int y,vector<vector<int>>& grid)\n    {\n        visit[x][y]=1;\n        ans++;\n\t\t//marking the color\n        grid[x][y]=val;\n        for(int i=0;i<4;i++){\n            int newx=x+dx[i];\n            int newy=y+dy[i];\n            if(newx>=0&&newx<n&&newy>=0&&newy<n&&!visit[newx][newy]&&grid[newx][newy]==1){\n                dfs(newx,newy,grid);\n            }\n        }\n        return;\n        \n        \n    }\n    int largestIsland(vector<vector<int>>& grid) {\n        n=grid.size();\n        int maxi=1;\n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                if(!visit[i][j]&&grid[i][j]==1){\n                    dfs(i,j,grid);\n\t\t\t\t\t//marking size of each color island\n                    mp[val]=ans;\n                    ans=0;\n                    val++;\n                    \n                }\n            }\n        }\n        if(mp.count(2))\n        maxi=mp[2];\n        \n        for(int i=0;i<n;i++){\n            for(int j=0;j<n;j++){\n                ans=0;\n                set<int>s;\n                if(grid[i][j]==0)\n                {for(int kk=0;kk<4;kk++){\n                    int newx=i+dx[kk];\n                    int newy=j+dy[kk];\n                    if(newx>=0&&newy<n&&newx<n&&newy>=0&&grid[newx][newy]>0&&s.find(grid[newx][newy])==s.end()){\n                        ans+=mp[grid[newx][newy]];\n                        s.insert(grid[newx][newy]);\n                    }\n                }\n                maxi=max(maxi,ans+1);}\n            }\n        }\n                    \n        return maxi;\n    }\n};\n```
[]