Easy to understand | Simple Approach
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    bool buildMatch(vector<vector<int>>& lcp, string& s)\n    {\n        int n=lcp.size();\n        vector<vector<int>> newLcp(n,vector<int>(n,0));\n        \n        //building lcp\n        for(int i=n-1;i>=0;i--)\n        {\n            for(int j=n-1;j>=0;j--)\n            {\n                \n                if(s[i]==s[j])\n                {\n                    int value=1;\n                    if(i+1<n && j+1<n )\n                    {\n                        value+=newLcp[i+1][j+1];\n                    }\n                    newLcp[i][j]=value;\n                }\n            }\n        }\n\n        //matching \n\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(lcp[i][j]!=newLcp[i][j])\n                {\n                    cout<<lcp[i][j]<<"  "<<newLcp[i][j]<<"  "<<i<<"  "<<j<<endl;\n                    return false;\n                }\n            }\n        }\n        return true;\n    }\n\n    int findParent(vector<int>& parent, int a)\n    {\n        if(parent[a]==-1)\n        {\n            return a;\n        }\n        else {\n            return parent[a]=findParent(parent,parent[a]);\n        }\n    }\n    void unionSet(vector<int>& parent,vector<int>& rank, int a, int b)\n    {\n        int parentA=findParent(parent,a);\n        int parentB=findParent(parent,b);\n\n        if(parentA!=parentB)\n        {\n            if(rank[parentA]>rank[parentB])\n            {\n                //A will be parent \n                parent[b]=parentA;\n            }\n            else{\n                parent[a]=parentB;\n            }\n        }\n\n    }\n    string findTheString(vector<vector<int>>& lcp) {\n        \n        int n=lcp.size();\n\n        vector<int> parent(n,-1),rank(n);\n\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(lcp[i][j]>0)\n                {\n                    unionSet(parent,rank,i,j);\n                }\n            }\n        }\n\n        unordered_map<int,char> mp;\n        string s;\n        char ch=\'a\';\n        for(int i=0;i<n;i++)\n        {\n            int parentI=findParent(parent,i);\n            if(mp.count(parentI)==0)\n            {\n                if(ch>=\'a\' && ch<=\'z\')\n                {\n                    mp[parentI]=ch++;\n                }\n                else {\n                    return "";\n                }\n                \n            }\n            s+=mp[parentI];\n        }\n\n        cout<<s<<endl;\n        if(buildMatch(lcp,s))\n        {\n            return s;\n        }\n        return "";\n    }\n};\n```
['C++']