C++ || DFS || GRAPH COLORING || BREIF ALGORITHM
```\nAlgorithm ->\n1) pick a color, color the group of 1\'s and simultaneously calculate the are of \n   those 1\'s and store the pair (color, area)\n2) travers
```\nAlgorithm ->\n1) pick a color, color the group of 1\'s and simultaneously calculate the are of \n   those 1\'s and store the pair (color, area)\n2) traverse the grid again and find the zero, if it is a zero than add the area of\n   colors on its 4 directions (NOTE: directions should be valid and we should not \n   add the redundant color).\n   \n   \nclass Solution {\npublic:\n    bool isValid(int i, int j, int n){\n        if(i < 0 || j < 0 || i >= n || j >=n) return false;\n        return true;\n    }\n    int dfs(vector<vector<int>> &grid, int i, int j, int color){\n        if(i < 0 || j < 0 || i >= grid.size() || j >= grid.size() || grid[i][j] != 1)\n            return 0;\n        \n        grid[i][j] = color;\n        return 1 + dfs(grid, i + 1, j, color) + dfs(grid, i, j + 1, color) + dfs(grid, i - 1, j, color) + dfs(grid, i, j - 1, color);\n        \n    }\n    int largestIsland(vector<vector<int>>& grid) {\n          int n = grid.size();\n          vector<int> colors (n * n + 2, 0);\n          int color = 2;\n          for(int i=0; i<n; i++){\n              for(int j=0; j<n; j++){\n                  if(grid[i][j] == 1){\n                      int area = dfs(grid, i, j, color);\n                      colors[color] = area;\n                      color++;\n                  }\n              }\n          }\n        \n         int area = 0;\n         \n        for(int i=0; i<n; i++){\n            for(int j=0; j<n; j++){\n                if(grid[i][j] == 0)\n                { set<int> col;\n                if(isValid(i+1, j, n)) col.insert(grid[i+1][j]);\n                if(isValid(i, j+1, n)) col.insert(grid[i][j+1]);\n                if(isValid(i, j-1, n)) col.insert(grid[i][j-1]);\n                if(isValid(i-1, j, n)) col.insert(grid[i-1][j]);\n                int cur_area = 1;\n                for(auto it : col) cur_area += (colors[(it)]);\n                area = max(area, cur_area);\n                }\n            }\n        }\n          return area == 0 ? n * n : area;\n    }\n};\n\n\n\n\n\n
['Depth-First Search', 'C']