DFS AND UNORDERED MAP USING KEY ...CPP
Complexity
Time complexity:O(N*M)

Space complexity:O(N*M)
Code
# Complexity
- Time complexity:O(N*M)
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:O(N*M)
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    int row,col;
    unordered_map<int,int>um;
    void helper(int i,int j,vector<vector<int>>&grid,vector<vector<int>>&visited,int key){
        if(i<0 || i>=row || j<0 || j>=col || grid[i][j]==0 || visited[i][j])return;
        grid[i][j]=key;
        visited[i][j]=1;
        helper(i+1,j,grid,visited,key);
        helper(i-1,j,grid,visited,key);
        helper(i,j+1,grid,visited,key);
        helper(i,j-1,grid,visited,key);
    }
    int largestIsland(vector<vector<int>>& grid) {
        row=grid.size(),col=grid[0].size();
        int key=1;
        vector<vector<int>>visited(row,vector<int>(col,0));
        for(int r=0;r<row;r++){
            for(int c=0;c<col;c++){
                if(grid[r][c]==1 && !visited[r][c]){
                    helper(r,c,grid,visited,key);
                    key++;
                }
            }
        }
        for(int r=0;r<row;r++){
            for(int c=0;c<col;c++){
                if(grid[r][c]){
                    um[grid[r][c]]++;
                }
            }
        }
        int ans=0;
        bool flag=false;
        for(int r=0;r<row;r++){
            for(int c=0;c<col;c++){
                if(!grid[r][c]){
                    flag=true;
                    unordered_set<int>us;
                    if(r-1>=0)us.insert(grid[r-1][c]);
                    if(r+1<row)us.insert(grid[r+1][c]);
                    if(c-1>=0)us.insert(grid[r][c-1]);
                    if(c+1<col)us.insert(grid[r][c+1]);
                    int area=1;
                    for(int x:us){
                        area+=um[x];
                    }ans=max(ans,area);
                }
            }
        }
        if(!flag)return row*col;
        return ans;
    }
};
```
['C++']