97.60% Time | 88.62% Space | C++
\nclass Solution {\npublic:\n    \n    string GetOverLapping(string a, string b){\n        \n        int M=0;\n        \n        int aplusb=0;\n            \n  
```\nclass Solution {\npublic:\n    \n    string GetOverLapping(string a, string b){\n        \n        int M=0;\n        \n        int aplusb=0;\n            \n        int bplusa=0;\n        \n        //string ans="";\n        \n        for(int i=1;i<=min(a.length(),b.length());i++){\n            if(a.compare(a.length()-i,i,b,0,i)==0){\n                if(i>M){\n                    M=i;\n                    bplusa=0;\n                    aplusb=1;\n                }\n            }     \n        }\n        \n        for(int i=1;i<=min(a.length(),b.length());i++){\n            if(b.compare(b.length()-i,i,a,0,i)==0){\n                if(i>M){\n                    M=i;\n                    bplusa=1;\n                    aplusb=0;\n                }\n            }     \n        }\n        \n        //cout<<aplusb<<" "<<bplusa<<endl;\n        if(aplusb){\n            //cout<<a.substr(0,a.length()-M)+b.substr(M)<<endl;\n            //cout<<a<<" "<<b<<" "<<M<<endl;\n            return a+b.substr(M);\n        }\n        else\n        {\n            //cout<<b.substr(0,b.length()-M)+a.substr(M)<<endl;\n            //cout<<b<<" "<<a<<" "<<M<<endl;\n            return b+a.substr(M);\n        }\n    }\n    \n    \n    string shortestSuperstring(vector<string>& A) {\n        \n        \n        vector <string> collection = A;\n        \n        while(1){\n            \n            if(collection.size()==1)\n                break;\n            \n            int maxSize = -1;\n            \n            int x = -1;\n            int y = -1;\n            \n            string mystr;\n            \n            for(int i=0;i<collection.size();i++){\n                for(int j=i+1;j<collection.size();j++){\n                    string f =  collection[i];\n                    string s = collection[j];\n                    \n                    string ovl = GetOverLapping(f,s);\n                    \n                    int saved = f.length()+s.length() - ovl.length();\n                    \n                    //maxSize = max(maxSize, saved);\n                    \n                    if(saved > maxSize){\n                        maxSize = saved;\n                        x=i;\n                        y=j;\n                        \n                        mystr = ovl;\n                    }\n                }\n            }\n            \n            \n            \n            string str1 = collection[x];\n            string str2 = collection[y];\n            \n            //cout<<str1<<" "<<str2<<endl;\n            collection.erase(collection.begin()+min(x,y));\n            collection.erase(collection.begin()+(max(x,y)-1));\n        \n            collection.push_back(mystr);\n            /*\n            for(auto x: collection)\n                cout<<x<<" ";\n            cout<<endl;\n            */\n            \n            \n            \n            \n        }\n        return collection[0];\n        \n    }\n};\n```
[]