c++ easy to understand with recursion and greedy approach
```\nclass Solution {\n    std::vector res;\npublic:\n    string shortestSuperstring(vector& arr) {\n        shortestSuperstringH(arr, arr.size());\n        int
```\nclass Solution {\n    std::vector<string> res;\npublic:\n    string shortestSuperstring(vector<string>& arr) {\n        shortestSuperstringH(arr, arr.size());\n        int m = INT_MAX;\n        int ind;\n      for(int i=0;i<res.size();i++){\n          if(res[i].size() < m){\n              ind = i;\n              m = res[i].size();\n          }\n      }\n        \n        return res[ind];\n        \n    }\n    \n    void shortestSuperstringH(vector<string> arr, int n) {\n \t\n        if (n == 1)\n        {\n                res.push_back(arr[0]);\n\n        }else{\n            // to store maximum overlap\n            int max = INT_MIN;\n\n            // to store array index of strings involved in maximum overlap\n            int p, q;\n\n            // to store resultant string after maximum overlap\n            vector<string> res_str;\n           \n            for (int i = 0; i < n; i++)\n            {\n                for (int j = i + 1; j < n; j++)\n                {\n                    vector<string> str;\n\n                    // r will store maximum length of the matching prefix and\n                    // suffix. str is passed by reference and store the result\n                    // string after maximum overlap of arr[i] and arr[j], if any\n                    int r = findOverlappingPair(arr[i], arr[j], str);\n\n                    // check for maximum overlap\n                    if (max < r)\n                    {\n                        max = r;\n                        res_str = str;\n                        p = i, q = j;\n                    }\n                    else if( max == r){\n                        if(str.size() < res_str.size()){\n                           res_str = str;\n                            p = i, q = j;\n                        }\n                        \n                    }\n\n                }\n            }\n\n           \n            // ignore last element in next cycle\n            n--;\n\n            // if no overlap, append arr[n] to arr[0]\n            if (max == INT_MIN){\n                 arr[0] += arr[n];\n                shortestSuperstringH(arr, n);\n            }\n            else\n            {\n                for(auto item:res_str){\n                    // copy resultant string to index p\n                    \n                    arr[p] = item;\n                    // copy string at last index to index q\n                    arr[q] = arr[n];\n                    shortestSuperstringH(arr, n);\n                }\n            }\n        }\n        \n    }\n    \n    int findOverlappingPair(string& s1, string& s2, vector<string>& str){\n            //compare s1 suffic and s2 prefix\n        int max = INT_MIN;\n        int m = s1.length();\n        int n = s2.length();\n\n        // check suffix of s1 matches with prefix of s2\n        for (int i = 1; i <= min(m, n); i++)\n        {\n            // compare last i characters in s1 with first i characters in s2\n            if (s1.compare(m - i, i, s2, 0, i) == 0)\n            {\n                if (max < i)\n                {\n                    //update max and str\n                    max = i;\n                    str.push_back({s1 + s2.substr(i)});\n                }\n            }\n        }\n\n        // check prefix of s1 matches with suffix of s2\n        for (int i = 1; i <= min(m, n); i++)\n        {\n            // compare first i characters in s1 with last i characters in s2\n            if (s1.compare(0, i, s2, n - i, i) == 0)\n            {\n                if (max <= i)\n                {\n                    //update max and str\n                    max = i;\n                    str.push_back({s2 + s1.substr(i)});\n                }\n            }\n        }\n\n        return max;\n    }\n};
[]