C++. DFS+BFS Easy Understand
My idea is to perform a DFS on the grid and find the area of each island. To differentiate each island we will assign a unique value which is variable  k in our
My idea is to perform a DFS on the grid and find the area of each island. To differentiate each island we will assign a unique value which is variable  ```k``` in our case. After finding all the islands and their areas, we will push the ```0\'s``` in the queue. From each 0, we will start a bfs of size 1 and check the number of islands present in the vicinity of this 0. With each check, we will update our ```area``` variable which denotes the max area connected.\n\n```\nclass Solution {\npublic:\n    int k=2;\n    unordered_map<int,int> mp;\n    int dx[4]={1,-1,0,0};\n    int dy[4]={0,0,1,-1};\n    int largestIsland(vector<vector<int>>& grid) {\n        int m=grid.size();\n        int n=grid[0].size();\n        k=2;\n        mp.clear();\n        int area=0;        \n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                if(grid[i][j]){\n                    dfs(grid,i,j);\n\t\t\t\t\t// We have to find the largest island in case there are no 0\'s in the grid\n                    area=max(area,mp[k]);\n                    k++;\n                }\n           }\n        }\n        queue<pair<int,int>> q;\n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                if(grid[i][j]==0)\n                    q.push({i,j});\n            }\n        }\n        while(!q.empty()){\n            auto p=q.front();\n            q.pop();\n            int x=p.first;\n            int y=p.second;\n\t\t\t// Unordered Set to make sure the islands are unique\n            unordered_set<int> s;\n            int tmp=0;\n            for(int i=0;i<4;i++){\n                int xx=dx[i]+x;\n                int yy=dy[i]+y;\n                if(xx<0||yy<0||xx>=m||yy>=n)    continue;\n                if(grid[xx][yy]==0)     continue;\n                int val=grid[xx][yy];\n                if(s.find(val)==s.end()){\n                    s.insert(val);\n                    tmp+=mp[val];\n                }\n            }\n            area=max(area,tmp+1);\n        }\n        return area;\n    }\n    \n    void dfs(vector<vector<int>> &grid, int i, int j){\n        if(i<0||j<0||i>=grid.size()||j>=grid[0].size())\n            return;\n        if(grid[i][j]!=1)\n            return;\n        mp[k]++;\n        grid[i][j]=k;\n        dfs(grid,i+1,j);\n        dfs(grid,i-1,j);\n        dfs(grid,i,j+1);\n        dfs(grid,i,j-1);\n    }\n};\n```
['Depth-First Search', 'Breadth-First Search', 'C++']