DFS based solution, using unique id for each island
\nfirst store all the islands in a list using bfs/dfs\nmark all the islands with a index within the grid\ncreate a hash map with key as index and size of island
\nfirst store all the islands in a list using bfs/dfs\nmark all the islands with a index within the grid\ncreate a hash map with key as index and size of island as the value\nThis will be done by itetrating over teh entire grid once O(m*n)\nwe will have to iterate over the grid again, checking for 0s and flipping\nevery 0 to 1 and see if the size of islands that can be formed. \nWe can do this either by iterating over the grid again (which will result\nin a TLE). So rather, we capture all the water cells in our first iteration \nand then only iterate on the water cells in the next run\n\n```\nclass Solution:\n    def largestIsland(self, grid: List[List[int]]) -> int:\n        \n        m, n = len(grid), len(grid[0])\n\n        def is_valid(i, j):\n            return 0 <= i < m and 0 <= j < n\n\n        def get_neighbors(i, j):\n            return [(i+1,j), (i-1,j), (i,j+1), (i,j-1)]\n\n        def dfs(i,j, index):\n            grid[i][j] = index\n            count = 1\n            for nei in get_neighbors(i, j):\n                x, y = nei\n                if is_valid(x, y) and grid[x][y] == 1:\n                    grid[x][y] = index\n                    count+=dfs(x,y, index)\n            return count\n\n        islands_map = {}\n        self.max_len = 0\n        water_cells = set()\n\n        index = 2\n        for i in range(m):\n            for j in range(n):\n                if grid[i][j] == 0:\n                    water_cells.add((i,j))\n                elif grid[i][j] == 1:\n                    size = dfs(i, j, index)\n                    islands_map[index] = size\n                    self.max_len = max(self.max_len, size)\n                    index+=1\n        \n        for cell in water_cells:\n            i, j = cell\n            # make it 1 and see, how big island can be formed idxs = set()\n            idxs = set()\n            island_len = 1\n            for nei in get_neighbors(i, j):\n                x, y = nei\n                if is_valid(x, y) and grid[x][y] in islands_map and grid[x][y] not in idxs:\n                    idxs.add(grid[x][y])\n                    island_len+=islands_map[grid[x][y]]\n\n            self.max_len = max(self.max_len, island_len)\n        return self.max_len\n```
['Depth-First Search', 'Python3']