DSU +Z function solution
 Describe your first thoughts on how to solve this problem.  \n\n# Approach\njust did what the question said with help of suitable ds and Z function\n\n\n\n\n\n
<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\njust did what the question said with help of suitable ds and Z function\n<!-- Describe your approach to solving the problem. -->\n\n\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass dsu():\n\tdef __init__(self,n):\n\t\tself.parent=[0]*(n)\n\t\tself.sz=[0]*(n)\n\n\tdef make_set(self,v):\n\t\tself.parent[v]=v\n\t\tself.sz[v]=1\n\n\tdef find_set(self,v):\n\t\tif v==self.parent[v]:\n\t\t\treturn v\n\t\tself.parent[v]=self.find_set(self.parent[v])\n\t\treturn self.parent[v]\n\n\tdef union(self,a,b):\n\t\ta=self.find_set(a)\n\t\tb=self.find_set(b)\n\t\tif a==b:\n\t\t\treturn\n\t\tif self.sz[a]<self.sz[b]:\n\t\t\ta,b=b,a\n\t\tself.parent[b]=a\n\t\tself.sz[a]+=self.sz[b]\n\n\tdef getsize(self,v):\n\t\treturn self.sz[self.find_set(v)]\ndef Z(s):\n\tn=len(s)\n\tx=0;y=0\n\tz=[0]*(n)\n\tfor i in range(1,n):\n\t\tz[i]=max(0,min(z[i-x],y-i+1))\n\t\twhile i+z[i]<n and s[z[i]]==s[i+z[i]]:\n\t\t\tx=i\n\t\t\ty=i+z[i]\n\t\t\tz[i]+=1\n\treturn z\nclass Solution:\n    def findTheString(self, l: List[List[int]]) -> str:\n        pairs=[]\n        n=len(l)\n        ds=dsu(n)\n        for i in range(n):\n            ds.make_set(i)\n        for i in range(n):\n            for j in range(n):\n                if l[i][j]:\n                    if ds.find_set(i)!=ds.find_set(j):\n                        ds.union(i,j)\n        st=defaultdict(list)\n        for i in range(n):\n            st[ds.find_set(i)].append(i)\n        vis=[0]*n\n        let="abcdefghijklmnopqrstuvwxyz"\n        print(len(let))\n        base=0\n        sr=["-1"]*n\n        for i in range(n):\n        \n            if vis[i]:\n                continue\n            for vl in st[ds.find_set(i)]:\n                vis[vl]=1\n                sr[vl]=let[base]\n            base+=1\n            if base>=26:\n                base=0\n                # return ""\n        fl=False\n        lc=[]\n        sr="".join(sr)\n        for i in range(n):\n            li=sr[i:]\n            x=li+"#"+sr\n            zr=Z(x)\n            print(zr)\n            lc.append(zr[len(li)+1:])\n        if lc!=l:\n            return ""\n        return sr\n```
['Python3']