Python || Easy || DSU
\nclass Solution:\n    def largestIsland(self, grid: List[List[int]]) -> int:\n        def find(u):\n            if u==parent[u]:\n                return u\n   
```\nclass Solution:\n    def largestIsland(self, grid: List[List[int]]) -> int:\n        def find(u):\n            if u==parent[u]:\n                return u\n            else:\n                parent[u]=find(parent[u])\n                return parent[u]\n        def union(u,v):\n            pu,pv=find(u),find(v)\n            if pu==pv:\n                return \n            if size[pv]>size[pu]:\n                parent[pu]=pv\n                size[pv]+=size[pu]\n            else:\n                parent[pv]=pu\n                size[pu]+=size[pv]\n        \n        n=len(grid)\n        parent=[i for i in range(n*n)]\n        size=[1 for i in range(n*n)]\n        for i in range(n):\n            for j in range(n):\n                if grid[i][j]:\n                    a=i*n+j\n                    for u,v in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:\n                        if 0<=u<n and 0<=v<n and grid[u][v]:\n                            b=u*n+v\n                            union(a,b)\n        m=0 \n        for i in range(n):\n            for j in range(n):\n                if grid[i][j]==0:\n#adjacent elemnts can have the same parent that\'s why we are using set\n                    t=set()\n                    c=1\n                    for u,v in [(i-1,j),(i+1,j),(i,j-1),(i,j+1)]:\n                        if 0<=u<n and 0<=v<n and grid[u][v]:\n                            a=u*n+v\n                            t.add(find(a))\n                    for x in t:\n                        c+=size[x]\n                    if c>m:\n                        m=c\n        for i in range(n*n):\n            m=max(m,size[find(i)])\n        return m\n```\n\n**An upvote will be encouraging**
['Depth-First Search', 'Union Find', 'Graph', 'Python', 'Python3']